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

Fix isinstance with type aliases to PEP 604 unions #17371

Merged
merged 4 commits into from
Jun 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
.
  • Loading branch information
hauntsaninja committed Jun 12, 2024
commit 2084372190e0b8d86cf4d1118705eb4cb6dbaa67
30 changes: 16 additions & 14 deletions test-data/unit/check-union-or-syntax.test
Original file line number Diff line number Diff line change
Expand Up @@ -209,21 +209,8 @@ from was_builtins import *
class mmap: ...
[builtins fixtures/type.pyi]

# TODO: Get this test to pass
[case testImplicit604TypeAliasWithCyclicImportNotInStub-xfail]
# flags: --python-version 3.10
from was_builtins import foo
reveal_type(foo) # N: Revealed type is "Union[builtins.str, was_mmap.mmap]"
[file was_builtins.py]
import was_mmap
WriteableBuffer = was_mmap.mmap
ReadableBuffer = str | WriteableBuffer
foo: ReadableBuffer
[file was_mmap.py]
from was_builtins import *
class mmap: ...

[case testTypeAliasWithNewUnionIsInstance]
# flags: --python-version 3.10
SimpleAlias = int | str

def foo(x: int | str | tuple):
Expand All @@ -238,3 +225,18 @@ ParameterizedAlias = str | list[str]
isinstance(5, str | list[str])
isinstance(5, ParameterizedAlias)
[builtins fixtures/type.pyi]


# TODO: Get this test to pass
[case testImplicit604TypeAliasWithCyclicImportNotInStub-xfail]
# flags: --python-version 3.10
from was_builtins import foo
reveal_type(foo) # N: Revealed type is "Union[builtins.str, was_mmap.mmap]"
[file was_builtins.py]
import was_mmap
WriteableBuffer = was_mmap.mmap
ReadableBuffer = str | WriteableBuffer
foo: ReadableBuffer
[file was_mmap.py]
from was_builtins import *
class mmap: ...
Loading