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
PEP 661 sentinel loses type information when reassigned #21971
$ mypy mre1.pymre1.py:6: error: Variable "mre1.ALIAS" is not valid as a type [valid-type]mre1.py:6: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliasesFound 1 error in 1 file (checked 1 source file)
mre1.py should type-check the same way mre2.py does. ALIAS is assigned directly from MISSING, so it should be recognized as the same sentinel.
Actual Behavior
$ mypy mre1.pymre1.py:6: error: Variable "mre1.ALIAS" is not valid as a type [valid-type]mre1.py:6: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliasesFound 1 error in 1 file (checked 1 source file)
Your Environment
Mypy version used: mypy 2.4.0+dev (master)
Mypy command-line flags: (none)
Mypy configuration options from mypy.ini (and other config files): (none)
Python version used: 3.15
Additional Context
This came up because Pydantic 2.14.0b2 re-exports its MISSING sentinel from pydantic_core as pydantic.MISSING:
$ mypy mre1.pymre1.py:3: error: Variable "pydantic.MISSING" is not valid as a type [valid-type]mre1.py:3: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliasesFound 1 error in 1 file (checked 1 source file)
pydantic_core.MISSING doesn't have this problem, since it's where MISSING is originally defined via Sentinel(...):
Activity
Recognize plain aliases of an existing sentinel as sentinel declarati…