You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Keep missing-attribute checking on the modules that survive (#293)
alias_getattr returns a __getattr__ typed -> Any, and mypy honors a
module __getattr__ assigned by tuple-unpacking. Assigning it plainly
therefore tells mypy that these modules answer EVERY attribute, which
switches off missing-attribute checking for the whole file. On
prefixes.py and bound_first_names.py that costs little -- they hold no
live constants. On titles.py and suffixes.py, which callers still
import from, it was a real loss. Same probe, master vs branch:
from nameparser.config.suffixes import SUFFIX_ACRONYM # typo
from nameparser.config.titles import TITLE # typo
master (18b0e49): 2 errors, with spelling suggestions
before this commit: Success: no issues found
The same bogus name against nameparser.config.particles, which has no
__getattr__, errored on both, so the probe discriminates. nameparser
ships py.typed, so this reached downstream callers.
Hiding the assignment in the else of an `if TYPE_CHECKING` guard that
declares the retired names restores it. All four alias-bearing modules
get the split, not just the two with live constants: the retired names
are still a supported import path, and typing one Any hands a caller
who is on that path an unchecked value -- silently, in THEIR code.
After the split every typo in the probe errors, including PREFIX and
BOUND_FIRST_NAME on the two shims, and reveal_type on all five retired
names is frozenset[str] where it was Any.
Runtime is untouched, and measured so: each retired name still resolves
is-identical to its 2.2 constant, still warns, is still in dir(), and
star imports still bind exactly the live and retired names.
The `# noqa: F822` on the four __all__ lists is now dead -- the
declarations bind the names for ruff too. Removing it is not just
tidying: with the suppression gone, deleting the TYPE_CHECKING branch
in 3.0 without deleting __all__ becomes an error instead of nothing.
Verified by `ruff check --ignore-noqa`, which reported all five F822s
before the split and none after; the ANN401 and E402 suppressions still
report there and stay.
Two follow-ons the suite found rather than I did. The retired-name scan
rejected the docstring example, which had spelled a real retired name
in the one file that serves no vocabulary -- the same trap the
stacklevel comment already documents -- so the example uses a
placeholder. And the star-import test derived "live constants" from the
name shape alone, which now also matches the imported TYPE_CHECKING; it
tests the value type as well.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
0 commit comments