Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.3k
Fix nondeterministic type checking by making join with explicit Protocol and type promotion commute#18402
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Fix nondeterministic type checking by making join with explicit Protocol and type promotion commute #18402
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
77679f8
Fix nondeterministic type checking involving noncommutative join
hauntsaninja 4cc6db9
Merge branch 'master' into nondet
hauntsaninja 3ef78e8
fix
hauntsaninja 0b18c18
efficiency
hauntsaninja 69c1a65
fix false positive
hauntsaninja 34e0a0c
fix test
hauntsaninja c120f88
Merge branch 'master' into nondet
hauntsaninja 4149882
test
hauntsaninja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3888,6 +3888,53 @@ def a4(x: List[str], y: List[Never]) -> None: | ||
| z1[1].append("asdf") # E: "object" has no attribute "append" | ||
| [builtins fixtures/dict.pyi] | ||
| [case testDeterminismCommutativityWithJoinInvolvingProtocolBaseAndPromotableType] | ||
| # flags: --python-version 3.11 | ||
| # Regression test for https://github.com/python/mypy/issues/16979#issuecomment-1982246306 | ||
| from __future__ import annotations | ||
| from typing import Any, Generic, Protocol, TypeVar, overload, cast | ||
| from typing_extensions import Never | ||
| T = TypeVar("T") | ||
| U = TypeVar("U") | ||
| class _SupportsCompare(Protocol): | ||
| def __lt__(self, other: Any, /) -> bool: | ||
| return True | ||
| class Comparable(_SupportsCompare): | ||
| pass | ||
| comparable: Comparable = Comparable() | ||
| from typing import _promote | ||
| class floatlike: | ||
| def __lt__(self, other: floatlike, /) -> bool: ... | ||
| @_promote(floatlike) | ||
| class intlike: | ||
| def __lt__(self, other: intlike, /) -> bool: ... | ||
| class A(Generic[T, U]): | ||
| @overload | ||
| def __init__(self: A[T, T], a: T, b: T, /) -> None: ... # type: ignore[overload-overlap] | ||
| @overload | ||
| def __init__(self: A[T, U], a: T, b: U, /) -> Never: ... | ||
| def __init__(self, *a) -> None: ... | ||
| def join(a: T, b: T) -> T: ... | ||
| reveal_type(join(intlike(), comparable)) # N: Revealed type is "__main__._SupportsCompare" | ||
| reveal_type(join(comparable, intlike())) # N: Revealed type is "__main__._SupportsCompare" | ||
| reveal_type(A(intlike(), comparable)) # N: Revealed type is "__main__.A[__main__._SupportsCompare, __main__._SupportsCompare]" | ||
hauntsaninja marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| reveal_type(A(comparable, intlike())) # N: Revealed type is "__main__.A[__main__._SupportsCompare, __main__._SupportsCompare]" | ||
| [builtins fixtures/tuple.pyi] | ||
| [typing fixtures/typing-medium.pyi] | ||
| [case testTupleJoinFallbackInference] | ||
| foo = [ | ||
| (1, ("a", "b")), | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4461,6 +4461,30 @@ f2(a4) # E: Argument 1 to "f2" has incompatible type "A4"; expected "P2" \ | ||
| # N: foo: expected setter type "C1", got "str" | ||
| [builtins fixtures/property.pyi] | ||
| [case testExplicitProtocolJoinPreference] | ||
| from typing import Protocol, TypeVar | ||
| T = TypeVar("T") | ||
| class Proto1(Protocol): | ||
| def foo(self) -> int: ... | ||
| class Proto2(Proto1): | ||
| def bar(self) -> str: ... | ||
| class Proto3(Proto2): | ||
| def baz(self) -> str: ... | ||
| class Base: ... | ||
| class A(Base, Proto3): ... | ||
| class B(Base, Proto3): ... | ||
| def join(a: T, b: T) -> T: ... | ||
| def main(a: A, b: B) -> None: | ||
| reveal_type(join(a, b)) # N: Revealed type is "__main__.Proto3" | ||
hauntsaninja marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| reveal_type(join(b, a)) # N: Revealed type is "__main__.Proto3" | ||
| [case testProtocolImplementationWithDescriptors] | ||
| from typing import Any, Protocol | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.