Skip to content

mypy can't find type defined inside a function. #4349

@asincero

Description

@asincero

Steps to reproduce

mypy can't seem to find a class defined inside a function. For example:

import typing

def foo() -> typing.Any:
    class Bar(typing.NamedTuple):
        member: str

    o = Bar(member='fee')
    return o

Current behavior

I get the following when I run mypy on the above code (saved in a file named "t1.py"):

t1.py:4: error: Name 'Bar' is not defined
t1.py:7: error: Missing positional arguments "typename", "fields", "verbose", "rename", "kwargs" in call to "Bar"

Expected behavior

No errors or warning from mypy.

mypy --version output

mypy 0.540

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions