Skip to content

[red-knot] is_subtype_of no longer implies is_assignable_to for all Type::Tuple types #17202

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

Closed
github-actions bot opened this issue Apr 4, 2025 · 3 comments · Fixed by #17213
Closed
Assignees
Labels
bug Something isn't working testing Related to testing Ruff itself ty Multi-file analysis & type inference

Comments

@github-actions
Copy link
Contributor

github-actions bot commented Apr 4, 2025

Failing property-test run listed here: https://github.com/astral-sh/ruff/actions/runs/14265011645

@github-actions github-actions bot added bug Something isn't working ty Multi-file analysis & type inference testing Related to testing Ruff itself labels Apr 4, 2025
@AlexWaygood
Copy link
Member

AlexWaygood commented Apr 4, 2025

failures:

---- types::property_tests::stable::all_type_pairs_are_assignable_to_their_union stdout ----

thread 'types::property_tests::stable::all_type_pairs_are_assignable_to_their_union' panicked at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/quickcheck-1.0.3/src/tester.rs:165:28:
[quickcheck] TEST FAILED. Arguments: (AlwaysFalsy, Tuple([]))
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- types::property_tests::stable::subtype_of_implies_assignable_to stdout ----

thread 'types::property_tests::stable::subtype_of_implies_assignable_to' panicked at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/quickcheck-1.0.3/src/tester.rs:165:28:
[quickcheck] TEST FAILED. Arguments: (Tuple([]), AlwaysFalsy)

@sharkdp I think this may be due to the changes we made to Type::is_assignable_to in #17168...?

@sharkdp
Copy link
Contributor

sharkdp commented Apr 4, 2025

@sharkdp I think this may be due to the changes we made to Type::is_assignable_to in #17168...?

That seems likely, thank you for the ping. I will look into it.

@AlexWaygood
Copy link
Member

AlexWaygood commented Apr 4, 2025

haven't tested it, but I think this might fix things:

diff --git a/crates/red_knot_python_semantic/src/types.rs b/crates/red_knot_python_semantic/src/types.rs
index 4f89feb57..17a43a519 100644
--- a/crates/red_knot_python_semantic/src/types.rs
+++ b/crates/red_knot_python_semantic/src/types.rs
@@ -1071,9 +1071,12 @@ impl<'db> Type<'db> {
             // This special case is required because the left-hand side tuple might be a
             // gradual type, so we can not rely on subtyping. This allows us to assign e.g.
             // `tuple[Any, int]` to `tuple`.
-            (Type::Tuple(_), _) => KnownClass::Tuple
-                .to_instance(db)
-                .is_assignable_to(db, target),
+            (Type::Tuple(_), _) => {
+                self.is_subtype_of(db, target)
+                    || KnownClass::Tuple
+                        .to_instance(db)
+                        .is_assignable_to(db, target)
+            }
 
             // `type[Any]` is assignable to any `type[...]` type, because `type[Any]` can
             // materialize to any `type[...]` type.

though there may also be a more elegant or more efficient solution.

@AlexWaygood AlexWaygood changed the title Daily property test run failed on Fri Apr 04 2025 [red-knot] is_subtype_of no longer implies is_assignable_to for all Type::Tuple types Apr 4, 2025
@sharkdp sharkdp self-assigned this Apr 4, 2025
@sharkdp sharkdp closed this as completed in 1a6a10b Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working testing Related to testing Ruff itself ty Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants