Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typing_extensions.NewType annotations are not recognized on < 3.10 (regression in 1.4.0) #16297

Closed
gschaffner opened this issue Oct 20, 2023 · 0 comments · Fixed by #16298
Closed
Labels
bug mypy got something wrong topic-newtype NewType

Comments

@gschaffner
Copy link
Contributor

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
@gschaffner gschaffner added the bug mypy got something wrong label Oct 20, 2023
@AlexWaygood AlexWaygood added the topic-newtype NewType label Oct 20, 2023
ilevkivskyi pushed a commit that referenced this issue Oct 20, 2023
<!--
Checklist:
- Read the [Contributing
Guidelines](https://github.com/python/mypy/blob/master/CONTRIBUTING.md)
- Add tests for all changed behaviour.
- If you can't add a test, please explain why and how you verified your
changes work.
- Make sure CI passes.
- Please do not force push to the PR once it has been reviewed.
-->

fixes #16297.

since the `.+_NAMES` constants in `types.py` are each referenced
multiple times while other examples like this (i.e. a `.+_NAMES`
tuple/set used only once) are inlined, I've inlined this one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-newtype NewType
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants