Skip to content

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

@vthemelis

Description

@vthemelis

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions