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

ReadOnly TypedDict items should be treated as covariant #17901

Closed
JukkaL opened this issue Oct 9, 2024 · 2 comments · Fixed by #17904
Closed

ReadOnly TypedDict items should be treated as covariant #17901

JukkaL opened this issue Oct 9, 2024 · 2 comments · Fixed by #17904
Assignees
Labels

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 9, 2024

ReadOnly was implemented in #17644. I think the implementation is incomplete -- this generates a false positive:

from typing import TypedDict
from typing_extensions import ReadOnly

class A(TypedDict):
    name: ReadOnly[str | None]

class B(TypedDict):
    name: str

def f(a: A) -> None: ...

b: B = {"name": "x"}
f(b)  # Incompatible type "B"; expected "A"

Extract from PEP 705:

Read-only items behave covariantly, as they cannot be mutated.

cc @sobolevn

@sobolevn
Copy link
Member

sobolevn commented Oct 9, 2024

Yes, I agree. I will fix this before 1.12

@JukkaL
Copy link
Collaborator Author

JukkaL commented Oct 9, 2024

@sobolevn I created a fix since it was pretty simple (#17904).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants