[red-knot] Add failing tests for iterating over maybe-iterable unions#14016
Merged
AlexWaygood merged 1 commit intomainfrom Oct 31, 2024
Merged
[red-knot] Add failing tests for iterating over maybe-iterable unions#14016AlexWaygood merged 1 commit intomainfrom
AlexWaygood merged 1 commit intomainfrom
Conversation
AlexWaygood
commented
Oct 31, 2024
| } | ||
|
|
||
| if let Type::Unknown | Type::Any = self { | ||
| if matches!(self, Type::Unknown | Type::Any | Type::Todo) { |
Member
Author
There was a problem hiding this comment.
we could possibly add a Type::is_dynamic() method to reduce the chances of bugs like this?
Comment on lines
1189
to
+1192
| // TODO: `type[Any]`? | ||
| Type::Any => Type::Todo, | ||
| Type::Any => Type::Any, | ||
| // TODO: `type[Unknown]`? | ||
| Type::Unknown => Type::Todo, | ||
| Type::Unknown => Type::Unknown, |
Member
Author
There was a problem hiding this comment.
Without this change, x in some of the loops I'm adding tests for was inferred as T | Todo rather than T | Unknown, because we lookup __iter__ and __next__ on the meta-type of an instance, and we had the meta-type of Unknown as being Todo. There is a TODO here (type[Unknown] would be more precise than Unknown), but it's not a big enough todo for us to infer Type::Todo in this situation, in my opinion 😄 Type::Unknown and Type::Any are better for now, in my opinion.
Contributor
|
carljm
approved these changes
Oct 31, 2024
sharkdp
added a commit
that referenced
this pull request
Nov 7, 2024
## Summary - Get rid of `Symbol::unwrap_or` (unclear semantics, not needed anymore) - Introduce `Type::call_dunder` - Emit new diagnostic for possibly-unbound `__iter__` methods - Better diagnostics for callables with possibly-unbound / possibly-non-callable `__call__` methods part of: #14022 closes #14016 ## Test Plan - Updated test for iterables with possibly-unbound `__iter__` methods. - New tests for callables
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This adds failing tests (with TODO comments) for the issues described in #14012, so that we can clearly see the limitations of our current inference. It fixes a couple of micro-bugs along the way, but nothing substantial, for the reasons described in #14012.
Test Plan
cargo test -p red_knot_python_semantic