Skip to content
New issue

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

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

Already on GitHub? # to your account

Variable "typing_extensions.ReadOnly" is not valid as a type #17801

Closed
MarcoGorelli opened this issue Sep 21, 2024 · 1 comment
Closed

Variable "typing_extensions.ReadOnly" is not valid as a type #17801

MarcoGorelli opened this issue Sep 21, 2024 · 1 comment
Labels
bug mypy got something wrong

Comments

@MarcoGorelli
Copy link
Contributor

MarcoGorelli commented Sep 21, 2024

Bug Report

ReadOnly is in typing-extensions but we can't use it with MyPy (but we can with PyRight)

To Reproduce

from typing import TypedDict, Hashable
from typing_extensions import ReadOnly

class Animal(TypedDict):
    name: ReadOnly[Hashable]
    
class Cat(TypedDict):
    name: str

cat: Animal(name='Toby')

https://gist.github.com/mypy-play/39923f5d02befb8d559583b702103391

Expected Behavior

No issues reported (which is what happens with PyRight)

Actual Behavior

main.py:5: error: Variable "typing_extensions.ReadOnly" is not valid as a type  [valid-type]
main.py:5: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
main.py:10: error: Invalid type comment or annotation  [valid-type]
main.py:10: note: Suggestion: use Animal[...] instead of Animal(...)
Found 2 errors in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.11.12
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.12
@MarcoGorelli MarcoGorelli added the bug mypy got something wrong label Sep 21, 2024
@MarcoGorelli MarcoGorelli changed the title ReadOnly Variable "typing_extensions.ReadOnly" is not valid as a type Sep 21, 2024
@brianschubert
Copy link
Collaborator

brianschubert commented Sep 21, 2024

PEP 705 / ReadOnly support is currently being tracked in #17264, and should land with #17644 🎉

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Sep 21, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants