Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typeguard doesn't check types like "a | b" #276

Closed
jingfeijia-tsy opened this issue Oct 26, 2022 · 4 comments
Closed

typeguard doesn't check types like "a | b" #276

jingfeijia-tsy opened this issue Oct 26, 2022 · 4 comments

Comments

@jingfeijia-tsy
Copy link

It seems typeguard doesn't support types like "a | b" that is introduced in PEP604.

To Reproduce

from typeguard import typechecked
from typing import Union

@typechecked
def f(x: int | float):
  print(x)

@typechecked
def g(x: Union[int, float]):
  print(x)

f("a")
g("a")

Expected behavior
Both should raise TypeError, but in reality f("a") just passed without raising an exception.

@antonagestam
Copy link
Contributor

This should be pretty easy to fix, we just need to add handling for a new type when available. See equivalent fixes here:

I guess it would be rather fitting if I provided a fix for this here as well, we'll see if I find the time.

Cheers

@agronholm
Copy link
Owner

This is already done in master, but I haven't had any time to devote on the project lately, thus no new release :(

@agronholm
Copy link
Owner

This is included in v3.0.0b1.

@supersergiy
Copy link
Contributor

supersergiy commented Jan 21, 2023

Exciting to see typeguard being worked on again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants