typing_extensions.NewType
annotations are not recognized on < 3.10 (regression in 1.4.0) #16297
Closed
Description
Bug Report
Mypy 1.4.0 introduced a regression where typing_extensions.NewType
annotations are not correctly recognized when --python-version
< 3.10.
this bisects to python/typeshed@a6d0aaf via python/typeshed#10205 via #15334. however this does not appear to be a typeshed issue; it's just that the typeshed change exposed a previously-hidden Mypy issue.
To Reproduce
# run with --python-version=3.9 or below, using mypy d11db28 or 1.4 or later
from typing_extensions import NewType
N = NewType("N", int)
x: N # error: Variable "eg_newtype.N" is not valid as a type [valid-type]
Expected Behavior
Mypy passes this example.
Actual Behavior
Mypy fails this example; see above.
Your Environment
- Mypy version used: 1.6.1 (compiled) and current master (uncompiled)
- Mypy command-line flags:
--python-version=3.9
- Mypy configuration options from
mypy.ini
(and other config files): none (i.e. using vendored typeshed) - Python version used: 3.12