Skip to content

don't allow overriding a namedtuple element #584

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

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
224ab4d
done with the text and feature
vagabond-0 Jun 27, 2025
776df8b
changed
vagabond-0 Jun 27, 2025
6d79519
move some match cases around
yangdanny97 Jun 26, 2025
c0140c3
Make BindingExpect 1 word bigger and avoid Box's
ndmitchell Jun 26, 2025
f3a1139
Push some Box down
ndmitchell Jun 26, 2025
0804080
Handle dataclass field kw_only overrides (#566)
pt2302 Jun 26, 2025
08f5893
Create a more flexible (private, for now) interface for `Calculation`.
stroxler Jun 26, 2025
67c81fb
Inline `calculate_with_recursive` logic to `get_idx`
stroxler Jun 26, 2025
6c7c86d
Define an ordering for `CalcId`
stroxler Jun 26, 2025
dc77fde
Create plumbing for cycle breaking
stroxler Jun 26, 2025
3da165b
Move `current_cycle` logic to `CalcStack`
stroxler Jun 26, 2025
d0de206
Use Vec1 for the cycle
stroxler Jun 26, 2025
2557d7a
Use `AnswersSolver::new` from `Answers`
stroxler Jun 26, 2025
b4c1033
Factor `AnswersSolver` out of `answers.rs`
stroxler Jun 26, 2025
0a603f6
Define the `Cycle` data structure, implement `Cycle::new`
stroxler Jun 26, 2025
62ebbe0
Add a `cycle_detected` method to `Cycles`
stroxler Jun 26, 2025
4c95daa
Add cycle state logic
stroxler Jun 26, 2025
ef5de94
Compute `current` in `get_idx`
stroxler Jun 26, 2025
f0638e9
Factor some things out of `get_idx`
stroxler Jun 26, 2025
e855ee6
Simplify `get_idx` a bit
stroxler Jun 26, 2025
83f2a8c
Simplify `get_idx` a bit more
stroxler Jun 26, 2025
c01ac04
Tweak `Cycles` apis a bit
stroxler Jun 26, 2025
cddb056
specify newlines for conformance output
yangdanny97 Jun 26, 2025
81d1f00
do not auto-import builtins
kinto0 Jun 26, 2025
bce8a9b
Fix a lint
ndmitchell Jun 26, 2025
129f6c3
Fix up test_find_module_prefixes (#576)
ndmitchell Jun 26, 2025
4990bf1
Make Unique/Var zero's with const
ndmitchell Jun 26, 2025
e057de1
Hardcode ::Recursive to Var
ndmitchell Jun 26, 2025
27b9752
Delete SolveRecursive
ndmitchell Jun 26, 2025
bba1d2a
Propagate TypedDict's update type hint to expression type inference
migeed-z Jun 26, 2025
f58d10f
make magic_dunder_attr lookup use get_possible_attribute_bases (#577)
yangdanny97 Jun 27, 2025
620c009
Implement ReadOnlyReason for specific error messages (#570)
Adist319 Jun 27, 2025
8a6d975
add mypy_primer to github CI (#565)
yangdanny97 Jun 27, 2025
0684127
Record a bug with Mapping.get
ndmitchell Jun 27, 2025
1e6ce50
Add extra cache clearing functionality for LSP
connernilsen Jun 27, 2025
e87a982
rebased
vagabond-0 Jun 27, 2025
a117840
Merge branch 'main' into issue#568
vagabond-0 Jun 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions conformance/third_party/conformance.exp
Original file line number Diff line number Diff line change
Expand Up @@ -7455,6 +7455,16 @@
"stop_column": 13,
"stop_line": 59
},
{
"code": -2,
"column": 5,
"concise_description": "Cannot override named tuple element `x`",
"description": "Cannot override named tuple element `x`",
"line": 79,
"name": "bad-override",
"stop_column": 6,
"stop_line": 79
},
{
"code": -2,
"column": 19,
Expand Down
4 changes: 1 addition & 3 deletions conformance/third_party/conformance.result
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,7 @@
],
"literals_parameterizations.py": [],
"literals_semantics.py": [],
"namedtuples_define_class.py": [
"Line 79: Expected 1 errors"
],
"namedtuples_define_class.py": [],
"namedtuples_define_functional.py": [],
"namedtuples_type_compat.py": [],
"namedtuples_usage.py": [],
Expand Down
10 changes: 5 additions & 5 deletions conformance/third_party/results.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"total": 136,
"pass": 60,
"fail": 76,
"pass_rate": 0.44,
"differences": 356,
"pass": 61,
"fail": 75,
"pass_rate": 0.45,
"differences": 355,
"passing": [
"aliases_explicit.py",
"aliases_newtype.py",
Expand Down Expand Up @@ -49,6 +49,7 @@
"historical_positional.py",
"literals_parameterizations.py",
"literals_semantics.py",
"namedtuples_define_class.py",
"namedtuples_define_functional.py",
"namedtuples_type_compat.py",
"namedtuples_usage.py",
Expand Down Expand Up @@ -114,7 +115,6 @@
"generics_variance.py": 12,
"literals_interactions.py": 2,
"literals_literalstring.py": 3,
"namedtuples_define_class.py": 1,
"narrowing_typeguard.py": 2,
"narrowing_typeis.py": 4,
"overloads_consistency.py": 2,
Expand Down
12 changes: 12 additions & 0 deletions pyrefly/lib/alt/class/class_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,18 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {

for (parent, parent_metadata) in parents {
parent_has_any = parent_has_any || parent_metadata.has_base_any();
// Don't allow overriding a namedtuple element
if let Some(named_tuple_metadata) = parent_metadata.named_tuple_metadata() {
if named_tuple_metadata.elements.contains(name) {
self.error(
errors,
range,
ErrorKind::BadOverride,
None,
format!("Cannot override named tuple element `{}`", name),
);
}
}
let Some(want_member) = self.get_class_member(parent.class_object(), name) else {
continue;
};
Expand Down
17 changes: 17 additions & 0 deletions pyrefly/lib/test/named_tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,20 @@ class Foo(NamedTuple):
y: str # E: NamedTuple field 'y' without a default may not follow NamedTuple field with a default
"#,
);

testcase!(
test_named_tuple_override_error,
r#"
from typing import NamedTuple

class A(NamedTuple):
x: int

class B(A):
x: int # E: Cannot override named tuple element `x`
y: int

class C(B):
y: int # OK
"#,
);