Repository navigation
[ty] Respect subclass shadowing for inherited NamedTuple fields - #24640
Merged
Merged
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 87.94%. The percentage of expected errors that received a diagnostic held steady at 83.21%. The number of fully passing files held steady at 79/133. |
Memory usage reportSummary
Significant changesClick to expand detailed breakdownprefect
sphinx
trio
flake8
|
|
charliermarsh
force-pushed
the
charlie/named-tuple-shadowing
branch
2 times, most recently
from
April 14, 2026 18:35
962b71a to
ce7056d
Compare
AlexWaygood
approved these changes
Apr 14, 2026
AlexWaygood
left a comment
Member
There was a problem hiding this comment.
Nice, I assumed it would be something like this
Comment on lines
+2267
to
+2268
| .keys() | ||
| .any(|field_name| field_name == name) |
Member
There was a problem hiding this comment.
Suggested change
| .keys() | |
| .any(|field_name| field_name == name) | |
| .contains_key(name) |
|
|
||
| /// `NamedTuple` fields are exposed via synthesized descriptors on the class rather than | ||
| /// instance attributes. If fields are unknown (dynamic), return `Any` for any attribute. | ||
| pub(super) fn own_instance_member(self, db: &'db dyn Db, _name: &str) -> Member<'db> { |
Member
There was a problem hiding this comment.
you could also just remove the argument, but I don't feel strongly
diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs
index ea809d830a..b0ca88fb50 100644
--- a/crates/ty_python_semantic/src/types/class.rs
+++ b/crates/ty_python_semantic/src/types/class.rs
@@ -1724,7 +1724,7 @@ impl<'db> ClassType<'db> {
dynamic.own_instance_member(db, name)
}
Self::NonGeneric(ClassLiteral::DynamicNamedTuple(namedtuple)) => {
- namedtuple.own_instance_member(db, name)
+ namedtuple.own_instance_member(db)
}
Self::NonGeneric(ClassLiteral::DynamicTypedDict(_)) => Member::default(),
Self::NonGeneric(ClassLiteral::DynamicEnum(enum_lit)) => {
diff --git a/crates/ty_python_semantic/src/types/class/named_tuple.rs b/crates/ty_python_semantic/src/types/class/named_tuple.rs
index a62f36403f..a2026a51a5 100644
--- a/crates/ty_python_semantic/src/types/class/named_tuple.rs
+++ b/crates/ty_python_semantic/src/types/class/named_tuple.rs
@@ -275,7 +275,7 @@ impl<'db> DynamicNamedTupleLiteral<'db> {
///
/// `NamedTuple` fields are exposed via synthesized descriptors on the class rather than
/// instance attributes. If fields are unknown (dynamic), return `Any` for any attribute.
- pub(super) fn own_instance_member(self, db: &'db dyn Db, _name: &str) -> Member<'db> {
+ pub(super) fn own_instance_member(self, db: &'db dyn Db) -> Member<'db> {
if !self.has_known_fields(db) {
return Member::definitely_declared(Type::any());
}
@@ -286,7 +286,7 @@ impl<'db> DynamicNamedTupleLiteral<'db> {
/// Look up an instance member by name (including superclasses).
pub(crate) fn instance_member(self, db: &'db dyn Db, name: &str) -> PlaceAndQualifiers<'db> {
// First check own instance members.
- let result = self.own_instance_member(db, name);
+ let result = self.own_instance_member(db);
if !result.is_undefined() {
return result.inner;
}
charliermarsh
marked this pull request as ready for review
April 14, 2026 19:18
charliermarsh
requested review from
carljm,
dcreager,
ibraheemdev and
sharkdp
as code owners
April 14, 2026 19:18
charliermarsh
force-pushed
the
charlie/named-tuple-shadowing
branch
from
April 14, 2026 19:23
ce7056d to
f131bb9
Compare
charliermarsh
enabled auto-merge (squash)
April 14, 2026 19:24
This was referenced Apr 27, 2026
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
Closes astral-sh/ty#3273.