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.
Reproducer: https://mypy-play.net/?gist=7a79f64ac9733542b571cc358f6d3165
import os
from pathlib import Path
from typing import Any
from typing_extensions import TypeAlias
Incomplete: TypeAlias = Any
A: 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.
Since mypy 1.20, passing a value whose type is an alias to
Any(e.g.Incomplete: TypeAlias = Any) as thedefaultargument ofos.environ.getcauses mypy to inferstr | Noneinstead ofAny, producing a spurious[arg-type]error at the use site.Reproducer: https://mypy-play.net/?gist=7a79f64ac9733542b571cc358f6d3165
Bisected to
30260ca57which added explicit_Environ.get/popoverloads where the first overload isdef get(self, key, default: None = None) -> AnyStr | None. Before that sync,_EnvironinheritedMapping.get, whose first overload took nodefaultargument, so 2-arg calls couldn't match it.Versions: broken on mypy ≥ 1.20.0; works on mypy ≤ 1.19.1.