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

Unexpected PEP 604 union behaviour when one of the types is shadowed #395

Closed
2 tasks done
vthemelis opened this issue Sep 3, 2023 · 0 comments
Closed
2 tasks done
Labels

Comments

@vthemelis
Copy link
Contributor

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

master - 041b0e3

Python version

Python 3.10.12

What happened?

When one of the arguments of the types in the union is shadowed, it should effectively be handled as Any but is currently effectively handled as an uninhabited type.

How can we reproduce the bug?

def test_function_with_union_where_one_of_the_types_is_shadowed():
    @typechecked
    def foo(int: int | None) -> int | None:
        return int

    # All the following should pass because the typechecker cannot 'see'
    # int-type as it's shadowed from the int-argument.
    # However, the only test that passes at the moment is `foo(None)`.
    assert foo(1) == 1
    assert foo(None) is None
    assert foo("foo") == "foo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant