Skip to content

"issubclass() arg 2 must be a class, a tuple of classes, or a union" with type argument #526

@bersbersbers

Description

@bersbersbers

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

Python version

3.13.2

What happened?

I'd expect python bug.py to pass. Instead:

(project) C:\Git\project>python bug.py
Traceback (most recent call last):
  File "C:\Git\project\bug.py", line 11, in <module>
    function_of_dtype(np.uint32)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "C:\Git\project\bug.py", line 9, in function_of_dtype
    def function_of_dtype(dtype: type[Integer]) -> None: ...
  File "C:\Git\project\.venv\Lib\site-packages\typeguard\_functions.py", line 137, in check_argument_types
    check_type_internal(value, annotation, memo)
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Git\project\.venv\Lib\site-packages\typeguard\_checkers.py", line 951, in check_type_internal
    checker(value, origin_type, args, memo)
    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Git\project\.venv\Lib\site-packages\typeguard\_checkers.py", line 503, in check_class
    elif not issubclass(value, expected_class):  # type: ignore[arg-type]
             ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
TypeError: issubclass() arg 2 must be a class, a tuple of classes, or a union

How can we reproduce the bug?

bug.py:

from typing import Any

import numpy as np
from typeguard import typechecked

type Integer = np.integer[Any]

@typechecked
def function_of_dtype(dtype: type[Integer]) -> None: ...

function_of_dtype(np.uint32)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions