Skip to content

False positive when checking <class 'types.GenericAlias'>(e.g.dict[str, str]) against type #432

@fefe982

Description

@fefe982

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

Python version

3.12.0

What happened?

With this file:

import typeguard

@typeguard.typechecked
def foo(t: type):
    pass

foo(dict[str,str])

typeguard reports:

Traceback (most recent call last):
  File "/****/test.py", line 7, in <module>
    foo(dict[str,str])
  File "/****/test.py", line 4, in foo
    def foo(t: type):
  File "/****/lib/python3.12/site-packages/typeguard/_functions.py", line 138, in check_argument_types
    check_type_internal(value, annotation, memo)
  File "/****/lib/python3.12/site-packages/typeguard/_checkers.py", line 759, in check_type_internal
    checker(value, origin_type, args, memo)
  File "/****/lib/python3.12/site-packages/typeguard/_checkers.py", line 438, in check_class
    raise TypeCheckError("is not a class")
typeguard.TypeCheckError: argument "t" (types.GenericAlias) is not a class

It should pass the test

How can we reproduce the bug?

With this file:

import typeguard

@typeguard.typechecked
def foo(t: type):
    pass

foo(dict[str,str])

typeguard reports:

Traceback (most recent call last):
  File "/****/test.py", line 7, in <module>
    foo(dict[str,str])
  File "/****/test.py", line 4, in foo
    def foo(t: type):
  File "/****/lib/python3.12/site-packages/typeguard/_functions.py", line 138, in check_argument_types
    check_type_internal(value, annotation, memo)
  File "/****/lib/python3.12/site-packages/typeguard/_checkers.py", line 759, in check_type_internal
    checker(value, origin_type, args, memo)
  File "/****/lib/python3.12/site-packages/typeguard/_checkers.py", line 438, in check_class
    raise TypeCheckError("is not a class")
typeguard.TypeCheckError: argument "t" (types.GenericAlias) is not a class

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions