hugovk
(Hugo van Kemenade)
April 25, 2023, 2:30pm
22
Yes, I linked to some above:
Searching the top 5k packages , they only show up in jsonargparse:
$ python3 ~/github/misc/cpython/search_pypi_top.py -q . "from calendar import .*(January|February)"
./jsonargparse-4.20.1.tar.gz: jsonargparse-4.20.1/jsonargparse_tests/test_signatures.py: from calendar import Calendar, January # type: ignore
Time: 0:00:16.076726
Found 1 matching lines in 1 projects
$ python3 ~/github/misc/cpython/search_pypi_top.py -q . "calendar\.(January|February)"
./jsonargparse-4.20.1.tar.gz: jsonargpars…
And:
And only 12 and 22 files found via GitHub’s beta code search.
I think people see things without leading underscores and quite reasonably think they’re public and use them.
2 Likes
Maybe someone could send a PR to jsonargparse
.
I don’t think that lack of underscores makes it “reasonable” to import anything from anywhere. I wish there was a consensus that __all__
defines what is public. The underscore convention affects import *
when __all__
is not used. When __all__
is used it should denote what is public.
EDIT: The actual code using this in json_argparse is just in the tests and even has a type: ignore
which is presumably because mypy/pyright complains about using a name that is not exposed in __all__
:
#!/usr/bin/env python3
import json
import os
import textwrap
import unittest
import warnings
from calendar import Calendar, January # type: ignore
from contextlib import redirect_stderr, redirect_stdout
from enum import Enum
from io import StringIO
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple, Union
import yaml
from jsonargparse import (
ActionConfigFile,
stoneleaf
(Ethan Furman)
April 25, 2023, 3:24pm
24
The are only two times when that is reasonable:
no __all__
is defined; or
the object in question is shown as public in the documentation
Well, that’s how Python treats it, so those who use Python would do well to also treat it like that.