agronholm / typeguard

Run-time type checker for Python
Other
1.52k stars 114 forks source link

cannot add a checker_lookup_function that operates on bytes #421

Closed Wizzerinus closed 7 months ago

Wizzerinus commented 10 months ago

Things to check first

Typeguard version

4.1.5

Python version

3.11.6

What happened?

See in the section below. I cannot really describe this bug efficiently aside from the title and that, apologies.

How can we reproduce the bug?

from typeguard import check_type, checker_lookup_functions

def validate_print(origin: type, params: tuple, annotation: tuple):
    print(f"validate_print: {origin=} {params=} {annotation=}")
    return None

checker_lookup_functions.append(validate_print)

check_type(100, int)    # prints the thing
check_type(b"", bytes)  # does not print the thing
agronholm commented 7 months ago

As the bytes type can be checked directly, there is no need for this. The checker_lookup_functions hook collection is not intended for custom validation messages.

agronholm commented 7 months ago

I should've added that the hook is intended for special types that are not checkable via a simple isinstance().