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

using Optional in TypedDict provides not consistent behaviour with PEP 589 #1549

Open
p-malecki opened this issue Dec 14, 2023 · 1 comment
Labels
bug cat: generics Generic, TypeVar, containers

Comments

@p-malecki
Copy link

Example Code

from typing_extensions import TypedDict
from typing import Optional


class A(TypedDict):
    x: Optional[int]

class B(TypedDict):
    x: int

def f(a: A) -> None:
    a['x'] = None

b: B = {'x': 0}
f(b)  # Type check error: 'B' not compatible with 'A'
b['x'] + 1  # Runtime error: None + 1

Expected Behavior

error: incompatible type argument in function f

Actual Behavior

Success: no errors found

Example works as expected in mypy.

@rchen152 rchen152 added bug cat: generics Generic, TypeVar, containers labels Dec 14, 2023
@rchen152
Copy link
Contributor

Agreed, pytype should flag this. We (the pytype devs) discussed this briefly, and we probably want to match mutable and immutable container types differently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cat: generics Generic, TypeVar, containers
Projects
None yet
Development

No branches or pull requests

2 participants