Skip to content

Dict[str, Any] - NameError: name 'Any_' is not defined. Did you mean: 'Any'? #362

@CodingTil

Description

@CodingTil

Things to check first

  • I have searched the existing issues and didn't find my bug already reported there

  • I have checked that my bug is still present in the latest release

Typeguard version

4.0.0

Python version

3.11.0

What happened?

When using Dict[str, Any] as a return type of a class method, you get the following error:

Traceback (most recent call last):
  File "/home/xyz/test.py", line 15, in <module>
    A().foo()
  File "/home/xyz/test.py", line 13, in foo
    def foo(self) -> Dict[str, Any]:
                          ^^^^^^^^
NameError: name 'Any_' is not defined. Did you mean: 'Any'?

This error does not occur in typeguard 3

How can we reproduce the bug?

from typeguard import typechecked
from typing import Any, Dict

# Works
@typechecked
def foo() -> Dict[str, Any]:
    return {}
foo()

# Does not work
class A:
    @typechecked
    def foo(self) -> Dict[str, Any]:
        return {}
A().foo()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions