[ty] Fix broken property tests for disjointness#18384
Conversation
|
(I added the "internal" label because the bug being fixed here hasn't appeared in any release, so this doesn't deserve an inclusion in the release notes.) |
|
59ef9e1 to
d72d3cb
Compare
|
Pretty interesting that there's a fair amount of mypy_primer fallout here, given that there was none on #18368! I'll go through it in a moment |
Here's a minimal repro of this hit. On from typing import Callable, reveal_type
def f(func: Callable | None):
x = reveal_type(func).__name__ if func is not None else 'bar' # revealed: `((...) -> Unknown) & ~None`
reveal_type(x) # revealed: `@Todo(map_with_boundness: intersections with negative contributions) | Literal["bar"]`This is because we do not infer that from typing import Callable, reveal_type
def f(func: Callable | None):
# error: Type `(...) -> Unknown` has no attribute `__name__`
x = reveal_type(func).__name__ if func is not None else 'bar' # revealed: `((...) -> Unknown)`
reveal_type(x) # revealed: `Unknown | Literal["bar"]`There's an open question about whether we should infer all The |
This one appears to be due to missing support for |
|
The sympy one looks correct to me. It's yet another case where we didn't see So I think all the mypy_primer hits are correct, and show that this PR improves our inference overall! |
* main: [ty] support callability of bound/constrained typevars (#18389) [ty] Minor tweaks to "list all members" docs and tests (#18388) [ty] Fix broken property tests for disjointness (#18384) [ty] List available members for a given type (#18251) [`airflow`] Add unsafe fix for module moved cases (`AIR312`) (#18363) Add a `SourceFile` to `OldDiagnostic` (#18356) Update salsa past generational id change (#18362) [`airflow`] Add unsafe fix for module moved cases (`AIR311`) (#18366) [`airflow`] Add unsafe fix for module moved cases (`AIR301`) (#18367) [ty] Improve tests for `site-packages` discovery (#18374) [ty] _typeshed.Self is not a special form (#18377) [ty] Callable types are disjoint from non-callable `@final` nominal instance types (#18368) [ty] Add diagnosis for function with no return statement but with return type annotation (#18359) [`airflow`] Add unsafe fix module moved cases (`AIR302`) (#18093) Rename `ruff_linter::Diagnostic` to `OldDiagnostic` (#18355) [`refurb`] Add coverage of `set` and `frozenset` calls (`FURB171`) (#18035)
Summary
Fixes astral-sh/ty#549
This assertion passes on
main:But this one does not:
https://play.ty.dev/d0a6b6c2-e492-4330-a866-2c4b0d51085a
The reason is that the
self.member_lookup_with_policy()call here is incorrect.selfmight not be theNominalInstancetype in thematch; it might be theCallabletype:ruff/crates/ty_python_semantic/src/types.rs
Lines 2180 to 2192 in ad2f667
I also removed an invalid TODO comment, as per the conversation in #18368 (comment)
Test Plan
QUICKCHECK_TESTS=100000 cargo test --release -p ty_python_semantic -- --ignored types::property_tests::stablepasses again