Skip to content

Allow narrowing with isinstance(x, str | int) (PEP 604 union types) #122

@MatthewMckee4

Description

@MatthewMckee4

Related:

What should be the expected revealed type here?

from typing_extensions import reveal_type

class A: ...
class B: ...
  
reveal_type(A | B) # revealed: `UnionType` or `type[A] | type[B]`?

Either way i think we must store the value of A | B as a Type::Union.

The way mypy handles this is it uses a uses_pep604_syntax flag in the UnionType class which allows it to reveal UnionType.

So, im not sure what the functionality should be

Metadata

Metadata

Assignees

No one assigned

    Labels

    narrowingrelated to flow-sensitive type narrowing

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions