Skip to content

Commit ae3cf27

Browse files
fangyi-zhoumeta-codesync[bot]
authored andcommitted
Allow typing.Mapping to form type aliases (#2031)
Summary: - Add `typing.Mapping` as a special export - Recongnise that subscript in `typing.Mapping` to be a type alias This fix is targeted to the failing conformance test suite (although I guess recursive aliases are still not working since recursive types are not supported afaik). Nonetheless, I think we need a longer term solution since there are other related "special exports" (e.g. `collections.abc.Mapping`, `typing.MutableMapping`, `typing.Sequence`). Pull Request resolved: #2031 Test Plan: `python test.py` Reviewed By: yangdanny97 Differential Revision: D90433864 Pulled By: stroxler fbshipit-source-id: d038440504ca4c061fae0f8571e6ec5983d937bf
1 parent ccc90cd commit ae3cf27

File tree

5 files changed

+9
-18
lines changed

5 files changed

+9
-18
lines changed

conformance/third_party/conformance.exp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -600,19 +600,7 @@
600600
"stop_line": 65
601601
}
602602
],
603-
"aliases_recursive.py": [
604-
{
605-
"code": -2,
606-
"column": 45,
607-
"concise_description": "Expected a type form, got instance of `Literal['RecursiveMapping']`",
608-
"description": "Expected a type form, got instance of `Literal['RecursiveMapping']`",
609-
"line": 42,
610-
"name": "not-a-type",
611-
"severity": "error",
612-
"stop_column": 63,
613-
"stop_line": 42
614-
}
615-
],
603+
"aliases_recursive.py": [],
616604
"aliases_type_statement.py": [
617605
{
618606
"code": -2,

conformance/third_party/conformance.result

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
"Line 63: Expected 1 errors",
2121
"Line 69: Expected 1 errors",
2222
"Line 72: Expected 1 errors",
23-
"Line 75: Expected 1 errors",
24-
"Line 42: Unexpected errors [\"Expected a type form, got instance of `Literal['RecursiveMapping']`\"]"
23+
"Line 75: Expected 1 errors"
2524
],
2625
"aliases_type_statement.py": [
2726
"Line 82: Expected 1 errors",

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": 106,
44
"fail": 32,
55
"pass_rate": 0.77,
6-
"differences": 132,
6+
"differences": 131,
77
"passing": [
88
"aliases_explicit.py",
99
"aliases_newtype.py",
@@ -114,7 +114,7 @@
114114
],
115115
"failing": {
116116
"aliases_implicit.py": 5,
117-
"aliases_recursive.py": 12,
117+
"aliases_recursive.py": 11,
118118
"aliases_type_statement.py": 4,
119119
"aliases_typealiastype.py": 4,
120120
"aliases_variance.py": 4,

pyrefly/lib/binding/target.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ impl<'a> BindingsBuilder<'a> {
545545
| SpecialExport::TypingTuple
546546
| SpecialExport::BuiltinsType
547547
| SpecialExport::TypingType
548+
| SpecialExport::TypingMapping
548549
)
549550
),
550551
Expr::BinOp(ExprBinOp {

pyrefly/lib/export/special.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub enum SpecialExport {
6969
BuiltinsFrozenset,
7070
BuiltinsFloat,
7171
Deprecated,
72+
TypingMapping,
7273
}
7374

7475
impl SpecialExport {
@@ -129,6 +130,7 @@ impl SpecialExport {
129130
"frozenset" => Some(Self::BuiltinsFrozenset),
130131
"float" => Some(Self::BuiltinsFloat),
131132
"deprecated" => Some(Self::Deprecated),
133+
"Mapping" => Some(Self::TypingMapping),
132134
_ => None,
133135
}
134136
}
@@ -158,7 +160,8 @@ impl SpecialExport {
158160
| Self::TypingType
159161
| Self::TypingDict
160162
| Self::TypingList
161-
| Self::TypingTuple => {
163+
| Self::TypingTuple
164+
| Self::TypingMapping => {
162165
matches!(m.as_str(), "typing" | "typing_extensions")
163166
}
164167
Self::CollectionsNamedTuple => matches!(m.as_str(), "collections"),

0 commit comments

Comments
 (0)