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

TypedDict totality ignored when instantiating a not type-hinted class variable typed dict #17174

Open
distrame opened this issue Apr 26, 2024 · 0 comments
Labels
bug mypy got something wrong

Comments

@distrame
Copy link

Bug Report

When instantiating a typeddict that was created as a class variable without any type hints and which has a not-required key, mypy thinks that all keys are required ignoring total=False and typing.NotRequired.

To Reproduce

import typing

class Dicts:
    class TF(typing.TypedDict, total=False):
        user_id: int

    class NR(typing.TypedDict):
        user_id: typing.NotRequired[int]

    TotalFalse = TF
    TotalFalse_Annotated: type[TF] = TF
    TotalFalse_TypeAlias: typing.TypeAlias = TF
    TotalFalse_ClassVar: typing.ClassVar[type[TF]] = TF
    TotalFalse_ClassVar_TypeAlias: typing.ClassVar[typing.TypeAlias] = TF

    NotRequired = NR
    NotRequired_Annotated: type[NR] = NR
    NotRequired_TypeAlias: typing.TypeAlias = NR
    NotRequired_ClassVar: typing.ClassVar[type[NR]] = NR
    NotRequired_ClassVar_TypeAlias: typing.ClassVar[typing.TypeAlias] = NR

dicts = Dicts()

dicts.TF()  # no error
dicts.TotalFalse()  # error: Missing named argument "user_id"  [call-arg]
dicts.TotalFalse_Annotated()  # no error
dicts.TotalFalse_TypeAlias()  # no error
dicts.TotalFalse_ClassVar()  # no error
dicts.TotalFalse_ClassVar_TypeAlias()  # no error

dicts.NR()  # no error
dicts.NotRequired()  # error: Missing named argument "user_id"  [call-arg]
dicts.NotRequired_Annotated()  # no error
dicts.NotRequired_TypeAlias()  # no error
dicts.NotRequired_ClassVar()  # no error
dicts.NotRequired_ClassVar_TypeAlias()  # no error

Expected Behavior

No errors

Actual Behavior

main.py:25: error: Missing named argument "user_id" [call-arg]
main.py:32: error: Missing named argument "user_id" [call-arg]

Your Environment

  • Mypy version used: 1.10.0
  • Python version used: 3.12
@distrame distrame added the bug mypy got something wrong label Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant