Skip to content

bug when inferring TypedDicts in method parameters #6522

Closed
@CesarLanderos

Description

@CesarLanderos

not sure if this is a bug or i could do something to fix the error mypy raises.

  • Are you reporting a bug, or opening a feature request?
    bug
  • Please insert below the code you are checking with mypy
class AlphaDict(TypedDict):
    kappa: int


def alpha(beta: AlphaDict) -> None:
    pass


class GamaDict(TypedDict, total=False):
    kappa: int


def gama(delta: GamaDict) -> None:
    pass


class EpsilonMutationDict(TypedDict):
    action: str
    kappa: int


def epsilon_resolver(theta: List[EpsilonMutationDict]) -> None:
    for zeta in theta:
        if zeta["action"] == "eta":
            alpha(zeta)
        elif zeta["action"] == "iota":
            gama(zeta)
  • What is the actual behavior/output?
    i get this error:

    error: Argument 1 to "gama" has incompatible type "EpsilonMutationDict"; expected "GamaDict"

  • What is the behavior/output you expect?
    I expect that mypy infers that the dict has the same kappa key in the dict, even tho it is an optional in GamaDict and in EpsilonMutationDict is not

  • What are the versions of mypy and Python you are using?
    python: 3.6.7
    mypy: 0.670

  • Do you see the same issue after installing mypy from Git master?
    have not tried that

  • What are the mypy flags you are using? (For example --strict-optional)

python_version = 3.6
ignore_missing_imports = True
disallow_untyped_defs = True
show_column_numbers = True
warn_redundant_casts = True
disallow_any_generics = True

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions