Skip to content

It seems like @typechecked decorator doesn't work with the new syntax for generics. #500

@Parki0

Description

@Parki0

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.4.1

Python version

3.13.0

What happened?

It seems like @typechecked decorator doesn't work with the new syntax for generics.
It works fine with the old one.

How can we reproduce the bug?

from typeguard import typechecked

class Gen[T]:
    @typechecked
    def bar(self, item: T):
        pass
	
gen = Gen[int]()
gen.bar(2) 

Get you this error message:

generics typeguard bug with new syntax.py:6: InstrumentationWarning: cannot find the target function in the AST -- not typechecking __main__.Gen.bar
  @typechecked

Works fine with the old one:

from typeguard import typechecked

from typing import TypeVar, Generic
T = TypeVar('T') 

class Gen(Generic[T]):
    @typechecked
    def bar(self, item: T):
        pass
	
gen = Gen[int]()
gen.bar(2) 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions