pyre-check icon indicating copy to clipboard operation
pyre-check copied to clipboard

Does not understand instantiation of TypedDict defined within same function

Open davidfstr opened this issue 3 years ago • 0 comments
trafficstars

Pyre Bug

Bug description Instantiation of a TypedDict which is defined within the same function (and not at the top-level of a module) is flagged incorrectly as a type error.

Reproduction steps

  • Create this file:
# test.py
from typing import TypedDict

#class Movie(TypedDict):
#    name: str
#    year: int

def foo() -> None:
    class Movie(TypedDict):
        name: str
        year: int

    _2 = Movie(name="Blade Runner", year=1982)

foo()
ƛ Found 1 type error!
test.py:12:9 Unexpected keyword [28]: Unexpected keyword argument `name` to call `object.__init__`.

If you move the definition of Movie to the top-level, the type error goes away.

Expected behavior There should be no type errors.

Additional context This bug was discovered while adding Pyre support to the trycast package.

davidfstr avatar Mar 20 '22 17:03 davidfstr