Skip to content

Commit 85f51b8

Browse files
committed
Updated TypedDict qualifier logic and conformance outputs
1 parent 7d509d9 commit 85f51b8

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

conformance/third_party/conformance.exp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10543,6 +10543,16 @@
1054310543
"stop_column": 24,
1054410544
"stop_line": 19
1054510545
},
10546+
{
10547+
"code": -2,
10548+
"column": 8,
10549+
"concise_description": "Cannot combine Required and NotRequired for a TypedDict field",
10550+
"description": "Cannot combine Required and NotRequired for a TypedDict field",
10551+
"line": 63,
10552+
"name": "invalid-annotation",
10553+
"stop_column": 34,
10554+
"stop_line": 63
10555+
},
1054610556
{
1054710557
"code": -2,
1054810558
"column": 75,

conformance/third_party/conformance.result

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,6 @@
613613
],
614614
"typeddicts_required.py": [
615615
"Line 62: Expected 1 errors",
616-
"Line 63: Expected 1 errors",
617616
"Line 74: Unexpected errors [\"Expected a type form, got instance of `Literal['RecursiveMovie']`\"]"
618617
],
619618
"typeddicts_type_consistency.py": [

conformance/third_party/results.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"pass": 55,
44
"fail": 81,
55
"pass_rate": 0.4,
6-
"differences": 407,
6+
"differences": 406,
77
"passing": [
88
"aliases_explicit.py",
99
"aliases_newtype.py",
@@ -140,7 +140,7 @@
140140
"typeddicts_readonly_consistency.py": 3,
141141
"typeddicts_readonly_inheritance.py": 7,
142142
"typeddicts_readonly_update.py": 2,
143-
"typeddicts_required.py": 3,
143+
"typeddicts_required.py": 2,
144144
"typeddicts_type_consistency.py": 2,
145145
"typeddicts_usage.py": 2
146146
},

pyrefly/lib/alt/solve.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -469,18 +469,28 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
469469
);
470470
}
471471

472-
let has_required = ann.qualifiers.contains(&Qualifier::Required);
473-
let has_not_required = ann.qualifiers.contains(&Qualifier::NotRequired);
474-
if (qualifier == Qualifier::Required && has_not_required)
475-
|| (qualifier == Qualifier::NotRequired && has_required)
476-
{
477-
self.error(
478-
errors,
479-
x.range(),
480-
ErrorKind::InvalidAnnotation,
481-
None,
482-
"Cannot combine Required and NotRequired for a TypedDict field".to_owned(),
483-
);
472+
if qualifier == Qualifier::Required {
473+
if ann.qualifiers.contains(&Qualifier::NotRequired) {
474+
self.error(
475+
errors,
476+
x.range(),
477+
ErrorKind::InvalidAnnotation,
478+
None,
479+
"Cannot combine Required and NotRequired for a TypedDict field"
480+
.to_owned(),
481+
);
482+
}
483+
} else if qualifier == Qualifier::NotRequired {
484+
if ann.qualifiers.contains(&Qualifier::Required) {
485+
self.error(
486+
errors,
487+
x.range(),
488+
ErrorKind::InvalidAnnotation,
489+
None,
490+
"Cannot combine Required and NotRequired for a TypedDict field"
491+
.to_owned(),
492+
);
493+
}
484494
}
485495

486496
ann.qualifiers.insert(0, qualifier);

0 commit comments

Comments
 (0)