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
{{ message }}
Repository navigation
[1.20 regression] _Environ.get(key, default) returns str | None when default is an alias to Any #21344
Since mypy 1.20, passing a value whose type is an alias to Any (e.g. Incomplete: TypeAlias = Any) as the default argument of os.environ.get causes mypy to infer str | None instead of Any, producing a spurious [arg-type] error at the use site.
importosfrompathlibimportPathfromtypingimportAnyfromtyping_extensionsimportTypeAliasIncomplete: TypeAlias=AnyA: Incomplete=Path()
reveal_type(A) # Any (good)B=os.environ.get('TEST', A)
reveal_type(B) # str | None (bad) (expected: Any)C=Path(B) # error: Argument 1 to "Path" has incompatible# type "str | None"; expected "str | PathLike[str]"
Bisected to 30260ca57 which added explicit _Environ.get/pop overloads where the first overload is def get(self, key, default: None = None) -> AnyStr | None. Before that sync, _Environ inherited Mapping.get, whose first overload took no default argument, so 2-arg calls couldn't match it.
Versions: broken on mypy ≥ 1.20.0; works on mypy ≤ 1.19.1.
changed the title [-]_Environ.get(key, default) returns str | None when default is an alias to Any[/-][+][1.20 regression] _Environ.get(key, default) returns str | None when default is an alias to Any[/+]on Apr 27, 2026
Activity
[-]_Environ.get(key, default) returns str | None when default is an alias to Any[/-][+][1.20 regression] _Environ.get(key, default) returns str | None when default is an alias to Any[/+]hauntsaninja commentedon Apr 27, 2026
Bisects to this typeshed sync #20505
hauntsaninja commentedon Apr 27, 2026
Looks like it'll be python/typeshed#15194
hauntsaninja commentedon Apr 27, 2026
So either typeshed needs to be changed, or the following behaviour of mypy needs to be changed:
This is similar to e.g. pyright
hauntsaninja commentedon Apr 27, 2026
Reminds me of python/typeshed#13222
pablogsal commentedon Apr 27, 2026
This is the reason i opened #21345 (sorry for not linking it here)