Skip to content

Commit cc2efcf

Browse files
committed
fix compile error after merging in main
1 parent 9d632e9 commit cc2efcf

File tree

8 files changed

+59
-25
lines changed

8 files changed

+59
-25
lines changed

crates/ruff_benchmark/benches/ty.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,29 @@ type KeyDiagnosticFields = (
5959
Severity,
6060
);
6161

62-
static EXPECTED_TOMLLIB_DIAGNOSTICS: &[KeyDiagnosticFields] = &[];
62+
static EXPECTED_TOMLLIB_DIAGNOSTICS: &[KeyDiagnosticFields] = &[
63+
(
64+
DiagnosticId::lint("invalid-argument-type"),
65+
Some("/src/tomllib/_parser.py"),
66+
Some(8224..8254),
67+
"Argument to this function is incorrect",
68+
Severity::Error,
69+
),
70+
(
71+
DiagnosticId::lint("invalid-argument-type"),
72+
Some("/src/tomllib/_parser.py"),
73+
Some(16914..16948),
74+
"Argument to this function is incorrect",
75+
Severity::Error,
76+
),
77+
(
78+
DiagnosticId::lint("invalid-argument-type"),
79+
Some("/src/tomllib/_parser.py"),
80+
Some(17319..17363),
81+
"Argument to this function is incorrect",
82+
Severity::Error,
83+
),
84+
];
6385

6486
fn tomllib_path(file: &TestFile) -> SystemPathBuf {
6587
SystemPathBuf::from("src").join(file.name())

crates/ty_python_semantic/resources/mdtest/annotations/self.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class Shape:
3333
reveal_type(self) # revealed: Unknown
3434
return self
3535

36-
reveal_type(Shape().nested_type()) # revealed: @Todo(specialized non-generic class)
36+
# TODO: should be `list[Shape]`
37+
reveal_type(Shape().nested_type()) # revealed: list[Self]
38+
3739
reveal_type(Shape().nested_func()) # revealed: Shape
3840

3941
class Circle(Shape):

crates/ty_python_semantic/resources/mdtest/annotations/stdlib_typing_aliases.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ def f(
4343
reveal_type(set_parametrized) # revealed: set[Unknown]
4444

4545
# TODO: revealed: frozenset[Unknown]
46-
reveal_type(frozen_set_bare) # revealed: frozenset
46+
reveal_type(frozen_set_bare) # revealed: frozenset[Unknown]
4747
# TODO: revealed: frozenset[str]
48-
reveal_type(frozen_set_parametrized) # revealed: frozenset
48+
reveal_type(frozen_set_parametrized) # revealed: frozenset[Unknown]
4949

5050
reveal_type(chain_map_bare) # revealed: ChainMap[Unknown, Unknown]
5151
# TODO: revealed: ChainMap[str, int]
@@ -97,8 +97,7 @@ reveal_type(SetSubclass.__mro__)
9797

9898
class FrozenSetSubclass(typing.FrozenSet): ...
9999

100-
# TODO: generic protocols
101-
# revealed: tuple[<class 'FrozenSetSubclass'>, <class 'frozenset'>, <class 'AbstractSet'>, <class 'Collection'>, <class 'Iterable'>, <class 'Container'>, @Todo(`Protocol[]` subscript), typing.Generic, <class 'object'>]
100+
# revealed: tuple[<class 'FrozenSetSubclass'>, <class 'frozenset[Unknown]'>, <class 'AbstractSet[Unknown]'>, <class 'Collection[Unknown]'>, <class 'Iterable[Unknown]'>, <class 'Container[Unknown]'>, typing.Protocol[_T_co], typing.Generic[_T_co], <class 'object'>]
102101
reveal_type(FrozenSetSubclass.__mro__)
103102

104103
####################

crates/ty_python_semantic/resources/mdtest/import/dunder_all.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ from subexporter import *
785785

786786
# TODO: Should be `list[str]`
787787
# TODO: Should we avoid including `Unknown` for this case?
788-
reveal_type(__all__) # revealed: Unknown | list
788+
reveal_type(__all__) # revealed: Unknown | list[Unknown]
789789

790790
__all__.append("B")
791791

crates/ty_python_semantic/resources/mdtest/subscript/tuple.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ python-version = "3.9"
8383
```py
8484
class A(tuple[int, str]): ...
8585

86-
reveal_type(A.__mro__) # revealed: tuple[<class 'A'>, <class 'tuple[@Todo(Generic tuple specializations), ...]'>, <class 'Sequence[@Todo(Generic tuple specializations)]'>, <class 'Reversible[@Todo(Generic tuple specializations)]'>, <class 'Collection[@Todo(Generic tuple specializations)]'>, <class 'Iterable[@Todo(Generic tuple specializations)]'>, <class 'Container[@Todo(Generic tuple specializations)]'>, typing.Protocol[_T_co], typing.Generic[_T_co], <class 'object'>]
86+
# revealed: tuple[<class 'A'>, <class 'tuple[@Todo(Generic tuple specializations), ...]'>, <class 'Sequence[@Todo(Generic tuple specializations)]'>, <class 'Reversible[@Todo(Generic tuple specializations)]'>, <class 'Collection[@Todo(Generic tuple specializations)]'>, <class 'Iterable[@Todo(Generic tuple specializations)]'>, <class 'Container[@Todo(Generic tuple specializations)]'>, typing.Protocol[_T_co], typing.Generic[_T_co], <class 'object'>]
87+
reveal_type(A.__mro__)
8788
```
8889

8990
## `typing.Tuple`

crates/ty_python_semantic/resources/mdtest/type_properties/is_subtype_of.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ static_assert(not is_subtype_of(tuple[B1, B2], tuple[()]))
151151
static_assert(not is_subtype_of(tuple[B1, B2], tuple[A1]))
152152
static_assert(not is_subtype_of(tuple[B1, B2], tuple[A1, A2, Unrelated]))
153153

154-
static_assert(is_subtype_of(tuple[int], tuple))
154+
# TODO: should pass
155+
static_assert(is_subtype_of(tuple[int], tuple[object, ...])) # error: [static-assert-error]
155156
```
156157

157158
## Union types

crates/ty_python_semantic/src/types/instance.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,9 @@ impl<'db> ProtocolInstanceType<'db> {
256256
Protocol::FromClass(class) => Self(Protocol::FromClass(
257257
class.apply_specialization(db, specialization),
258258
)),
259-
Protocol::Synthesized(synthesized) => {
260-
Self(Protocol::Synthesized(SynthesizedProtocolType::new(
261-
db,
262-
synthesized
263-
.interface(db)
264-
.clone()
265-
.apply_specialization(db, specialization),
266-
)))
267-
}
259+
Protocol::Synthesized(synthesized) => Self(Protocol::Synthesized(
260+
synthesized.apply_specialization(db, specialization),
261+
)),
268262
}
269263
}
270264
}
@@ -294,6 +288,7 @@ impl<'db> Protocol<'db> {
294288

295289
mod synthesized_protocol {
296290
use crate::db::Db;
291+
use crate::types::generics::Specialization;
297292
use crate::types::protocol_class::ProtocolInterface;
298293

299294
/// A "synthesized" protocol type that is dissociated from a class definition in source code.
@@ -313,6 +308,14 @@ mod synthesized_protocol {
313308
Self(interface.normalized(db))
314309
}
315310

311+
pub(super) fn apply_specialization(
312+
self,
313+
db: &'db dyn Db,
314+
specialization: Specialization<'db>,
315+
) -> Self {
316+
Self(self.0.specialized_and_normalized(db, specialization))
317+
}
318+
316319
pub(in crate::types) fn interface(self) -> ProtocolInterface<'db> {
317320
self.0
318321
}

crates/ty_python_semantic/src/types/protocol_class.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,22 @@ impl<'db> ProtocolInterface<'db> {
117117
)
118118
}
119119

120-
pub(super) fn apply_specialization(
120+
pub(super) fn specialized_and_normalized(
121121
self,
122122
db: &'db dyn Db,
123123
specialization: Specialization<'db>,
124124
) -> Self {
125-
Self(
126-
self.0
127-
.into_iter()
128-
.map(|(name, data)| (name, data.apply_specialization(db, specialization)))
129-
.collect(),
125+
Self::new(
126+
db,
127+
self._members(db)
128+
.iter()
129+
.map(|(name, data)| {
130+
(
131+
name.clone(),
132+
data.apply_specialization(db, specialization).normalized(db),
133+
)
134+
})
135+
.collect::<BTreeMap<_, _>>(),
130136
)
131137
}
132138
}
@@ -145,7 +151,7 @@ impl<'db> ProtocolMemberData<'db> {
145151
}
146152
}
147153

148-
fn apply_specialization(self, db: &'db dyn Db, specialization: Specialization<'db>) -> Self {
154+
fn apply_specialization(&self, db: &'db dyn Db, specialization: Specialization<'db>) -> Self {
149155
Self {
150156
ty: self.ty.apply_specialization(db, specialization),
151157
qualifiers: self.qualifiers,

0 commit comments

Comments
 (0)