agronholm / typeguard

Run-time type checker for Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

check_type(True, float) == True

juliendubost opened this issue · comments

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

Python version

3.11

What happened?

I noticed a strange behavior of check_type i can't get to explain

check_type(True, int) pass : since bool is a subclass of int it can make sense, isinstance(True, int) == True

But, this should raise TypeCheckError
check_type(True, float) pass whereas isinstance(True,float) == False

How can we reproduce the bug?

from typeguard import check_type
check_type(True, float)  # pass

What is your expectation of the outcome of check_type(1, float)?

@agronholm => i would expect a TypeCheckError to be raised since isinstance(1, float) return False.

What do you think ?

I don't think it should raise TypeCheckError because PEP 484 says that int should pass as a float, and since bool is also an int, check_type(True, float) should also pass.

And mypy agrees, so I'm closing this.

I see, thanks for your reply 👍