[ty] Use a more lenient fallback type for failed namedtuple() and NamedTuple calls#22765
Merged
AlexWaygood merged 1 commit intomainfrom Jan 21, 2026
Merged
Conversation
AlexWaygood
commented
Jan 20, 2026
Comment on lines
-6596
to
+6615
| let find_keyword = |name: &str| -> Option<&ast::Keyword> { | ||
| keywords | ||
| .iter() | ||
| .find(|kw| kw.arg.as_ref().is_some_and(|arg| arg.id.as_str() == name)) | ||
| }; | ||
| let typename_kw = find_keyword("typename"); | ||
| let field_names_kw = find_keyword("field_names"); | ||
| let typename_kw = call_expr.arguments.find_keyword("typename"); | ||
| let field_names_kw = call_expr.arguments.find_keyword("field_names"); |
Member
Author
There was a problem hiding this comment.
drive-by simplification; no functional change to this bit
Typing conformance resultsNo changes detected ✅ |
|
e1cd316 to
384c240
Compare
charliermarsh
approved these changes
Jan 20, 2026
Member
charliermarsh
left a comment
There was a problem hiding this comment.
Seems reasonable (assuming tests pass and ecosystem changes are clean).
…NamedTuple` calls
384c240 to
045c288
Compare
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 is stacked on top of #22718; review that first.
Currently if a user makes a bad
NamedTuple()call like this:then we emit errors on both calls: one correct error for the bad
NamedTuple()call (it's missing required arguments), and then another spurious error on theBad1()call:The reason for this second, spurious error is that we inferred
type[NamedTupleFallback]for the result of theBad1()call, andNamedTupleFallbackhas this__init__signature, which isn't appropriate in this context -- it actually reflects the arguments you need to pass to theNamedTuplefunction itself in order to create aNamedTupleclass, not the signature of the constructors that allNamedTupleclasses have:ruff/crates/ty_vendored/vendor/typeshed/stdlib/_typeshed/_type_checker_internals.pyi
Lines 63 to 69 in 7e1f07e
This PR updates the fallback type we use when
NamedTupleparsing fails, so that it's more lenient and the spurious error is no longer emitted.Test Plan
mdtests updated