Skip to content

Commit b22cc1a

Browse files
committed
nits
1 parent 26c25be commit b22cc1a

File tree

5 files changed

+36
-35
lines changed

5 files changed

+36
-35
lines changed

crates/ty_python_semantic/src/types.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use crate::types::mro::{Mro, MroError, MroIterator};
6666
pub(crate) use crate::types::narrow::infer_narrowing_constraint;
6767
use crate::types::signatures::{ParameterForm, walk_signature};
6868
use crate::types::tuple::TupleSpec;
69-
use crate::types::typed_dict::{SynthesizedTypedDictType, TypedDictSchema};
69+
use crate::types::typed_dict::{FunctionalTypedDictType, TypedDictSchema};
7070
pub(crate) use crate::types::typed_dict::{TypedDictParams, TypedDictType, walk_typed_dict_type};
7171
use crate::types::variance::{TypeVarVariance, VarianceInferable};
7272
use crate::types::visitor::any_over_type;
@@ -1010,14 +1010,14 @@ impl<'db> Type<'db> {
10101010
}
10111011
}
10121012

1013-
/// Turn a typed dict class literal or synthesized type dict type into a `TypedDictType`.
1013+
/// Turn a typed dict class literal or functional type dict type into a `TypedDictType`.
10141014
pub(crate) fn to_typed_dict_type(self, db: &'db dyn Db) -> Option<TypedDictType<'db>> {
10151015
match self {
10161016
Type::ClassLiteral(class_literal) if class_literal.is_typed_dict(db) => Some(
10171017
TypedDictType::from_class(ClassType::NonGeneric(class_literal)),
10181018
),
10191019
Type::KnownInstance(KnownInstanceType::TypedDictType(typed_dict)) => {
1020-
Some(TypedDictType::Synthesized(typed_dict))
1020+
Some(TypedDictType::Functional(typed_dict))
10211021
}
10221022
_ => None,
10231023
}
@@ -2993,7 +2993,7 @@ impl<'db> Type<'db> {
29932993
) -> PlaceAndQualifiers<'db> {
29942994
tracing::trace!("class_member: {}.{}", self.display(db), name);
29952995

2996-
if let Type::TypedDict(TypedDictType::Synthesized(typed_dict)) = self
2996+
if let Type::TypedDict(TypedDictType::Functional(typed_dict)) = self
29972997
&& let Some(member) =
29982998
TypedDictType::synthesized_member(db, self, typed_dict.items(db), &name)
29992999
{
@@ -4875,7 +4875,7 @@ impl<'db> Type<'db> {
48754875
Parameter::keyword_variadic(Name::new_static("kwargs"))
48764876
.with_annotated_type(Type::any()),
48774877
]),
4878-
Some(Type::TypedDict(TypedDictType::Synthesized(typed_dict))),
4878+
Some(Type::TypedDict(TypedDictType::Functional(typed_dict))),
48794879
)],
48804880
)
48814881
.into()
@@ -5685,7 +5685,7 @@ impl<'db> Type<'db> {
56855685
.unwrap_or(*self))
56865686
}
56875687
KnownInstanceType::TypedDictType(typed_dict) => {
5688-
Ok(Type::TypedDict(TypedDictType::Synthesized(*typed_dict)))
5688+
Ok(Type::TypedDict(TypedDictType::Functional(*typed_dict)))
56895689
}
56905690
KnownInstanceType::TypedDictSchema(_) => Err(InvalidTypeExpressionError {
56915691
invalid_expressions: smallvec::smallvec![InvalidTypeExpression::InvalidType(
@@ -6543,8 +6543,9 @@ impl<'db> Type<'db> {
65436543
},
65446544

65456545
Type::TypedDict(typed_dict) => match typed_dict {
6546-
TypedDictType::FromClass(class) => Some(TypeDefinition::Class(class.definition(db))),
6547-
TypedDictType::Synthesized(_) => None,
6546+
TypedDictType::ClassBased(class) => Some(TypeDefinition::Class(class.definition(db))),
6547+
// TODO: Support go-to-definition for functional `TypedDict`s.
6548+
TypedDictType::Functional(_) => None,
65486549
}
65496550

65506551
Self::Union(_) | Self::Intersection(_) => None,
@@ -6893,8 +6894,8 @@ pub enum KnownInstanceType<'db> {
68936894
/// A single instance of `typing.TypeAliasType` (PEP 695 type alias)
68946895
TypeAliasType(TypeAliasType<'db>),
68956896

6896-
/// A single instance of `typing.TypedDict`.
6897-
TypedDictType(SynthesizedTypedDictType<'db>),
6897+
/// A single class object created using the `typing.TypedDict` functional syntax
6898+
TypedDictType(FunctionalTypedDictType<'db>),
68986899

68996900
/// An internal type representing the dictionary literal argument to the functional `TypedDict`
69006901
/// constructor.
@@ -6928,7 +6929,7 @@ fn walk_known_instance_type<'db, V: visitor::TypeVisitor<'db> + ?Sized>(
69286929
visitor.visit_type_alias_type(db, type_alias);
69296930
}
69306931
KnownInstanceType::TypedDictType(typed_dict) => {
6931-
visitor.visit_typed_dict_type(db, TypedDictType::Synthesized(typed_dict));
6932+
visitor.visit_typed_dict_type(db, TypedDictType::Functional(typed_dict));
69326933
}
69336934
KnownInstanceType::Deprecated(_)
69346935
| KnownInstanceType::ConstraintSet(_)

crates/ty_python_semantic/src/types/call/bind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::types::function::{
2929
use crate::types::generics::{Specialization, SpecializationBuilder, SpecializationError};
3030
use crate::types::signatures::{Parameter, ParameterForm, ParameterKind, Parameters};
3131
use crate::types::tuple::{TupleLength, TupleType};
32-
use crate::types::typed_dict::SynthesizedTypedDictType;
32+
use crate::types::typed_dict::FunctionalTypedDictType;
3333
use crate::types::{
3434
BoundMethodType, ClassLiteral, DataclassParams, FieldInstance, KnownBoundMethodType,
3535
KnownClass, KnownInstanceType, MemberLookupPolicy, PropertyInstanceType, SpecialFormType,
@@ -1137,7 +1137,7 @@ impl<'db> Bindings<'db> {
11371137
.collect::<FxOrderMap<_, _>>();
11381138

11391139
overload.set_return_type(Type::KnownInstance(
1140-
KnownInstanceType::TypedDictType(SynthesizedTypedDictType::new(
1140+
KnownInstanceType::TypedDictType(FunctionalTypedDictType::new(
11411141
db,
11421142
Name::new(name.value(db)),
11431143
params,

crates/ty_python_semantic/src/types/class_base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl<'db> ClassBase<'db> {
173173
| KnownInstanceType::Deprecated(_)
174174
| KnownInstanceType::Field(_)
175175
| KnownInstanceType::ConstraintSet(_) => None,
176-
// TODO: Inherit the fields of synthesized `TypedDict`s.
176+
// TODO: Inherit the fields of functional `TypedDict`s.
177177
KnownInstanceType::TypedDictType(_) => Some(Self::TypedDict),
178178
},
179179

crates/ty_python_semantic/src/types/display.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,12 +512,12 @@ impl Display for DisplayRepresentation<'_> {
512512
}
513513

514514
Type::TypedDict(typed_dict) => match typed_dict {
515-
TypedDictType::FromClass(class) => class
515+
TypedDictType::ClassBased(class) => class
516516
.class_literal(self.db)
517517
.0
518518
.display_with(self.db, self.settings.clone())
519519
.fmt(f),
520-
TypedDictType::Synthesized(synthesized) => synthesized.name(self.db).fmt(f),
520+
TypedDictType::Functional(synthesized) => synthesized.name(self.db).fmt(f),
521521
},
522522

523523
Type::TypeAlias(alias) => f.write_str(alias.name(self.db)),

crates/ty_python_semantic/src/types/typed_dict.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,21 @@ impl Default for TypedDictParams {
5151
pub enum TypedDictType<'db> {
5252
/// A reference to the class (inheriting from `typing.TypedDict`) that specifies the
5353
/// schema of this `TypedDict`.
54-
FromClass(ClassType<'db>),
54+
ClassBased(ClassType<'db>),
5555

5656
/// A `TypedDict` created using the functional syntax.
57-
Synthesized(SynthesizedTypedDictType<'db>),
57+
Functional(FunctionalTypedDictType<'db>),
5858
}
5959

6060
impl<'db> TypedDictType<'db> {
6161
pub(crate) fn from_class(class: ClassType<'db>) -> Self {
62-
TypedDictType::FromClass(class)
62+
TypedDictType::ClassBased(class)
6363
}
6464

6565
pub(crate) fn items(&self, db: &'db dyn Db) -> Cow<'db, FxOrderMap<Name, Field<'db>>> {
6666
match self {
67-
TypedDictType::Synthesized(synthesized) => Cow::Borrowed(synthesized.items(db)),
68-
TypedDictType::FromClass(class) => {
67+
TypedDictType::Functional(functional) => Cow::Borrowed(functional.items(db)),
68+
TypedDictType::ClassBased(class) => {
6969
let (class_literal, specialization) = class.class_literal(db);
7070
Cow::Owned(class_literal.fields(db, specialization, CodeGeneratorKind::TypedDict))
7171
}
@@ -77,8 +77,8 @@ impl<'db> TypedDictType<'db> {
7777
// `TypedDict` instances are instances of `dict` at runtime, but its important that we
7878
// understand a more specific meta type in order to correctly handle `__getitem__`.
7979
match self {
80-
TypedDictType::FromClass(class) => SubclassOfType::from(db, class),
81-
TypedDictType::Synthesized(_) => KnownClass::TypedDictFallback.to_class_literal(db),
80+
TypedDictType::ClassBased(class) => SubclassOfType::from(db, class),
81+
TypedDictType::Functional(_) => KnownClass::TypedDictFallback.to_class_literal(db),
8282
}
8383
}
8484

@@ -90,11 +90,11 @@ impl<'db> TypedDictType<'db> {
9090
) -> Self {
9191
// TODO: Materialization of gradual TypedDicts needs more logic
9292
match self {
93-
TypedDictType::FromClass(class) => {
94-
TypedDictType::FromClass(class.apply_type_mapping_impl(db, type_mapping, visitor))
93+
TypedDictType::ClassBased(class) => {
94+
TypedDictType::ClassBased(class.apply_type_mapping_impl(db, type_mapping, visitor))
9595
}
96-
TypedDictType::Synthesized(synthesized) => TypedDictType::Synthesized(
97-
synthesized.apply_type_mapping_impl(db, type_mapping, visitor),
96+
TypedDictType::Functional(functional) => TypedDictType::Functional(
97+
functional.apply_type_mapping_impl(db, type_mapping, visitor),
9898
),
9999
}
100100
}
@@ -409,9 +409,9 @@ pub struct TypedDictSchemaField<'db> {
409409
pub(crate) is_read_only: bool,
410410
}
411411

412-
#[salsa::interned(debug, heap_size=SynthesizedTypedDictType::heap_size)]
412+
#[salsa::interned(debug, heap_size=FunctionalTypedDictType::heap_size)]
413413
#[derive(PartialOrd, Ord)]
414-
pub struct SynthesizedTypedDictType<'db> {
414+
pub struct FunctionalTypedDictType<'db> {
415415
pub(crate) name: Name,
416416

417417
pub(crate) params: TypedDictParams,
@@ -421,9 +421,9 @@ pub struct SynthesizedTypedDictType<'db> {
421421
}
422422

423423
// The Salsa heap is tracked separately.
424-
impl get_size2::GetSize for SynthesizedTypedDictType<'_> {}
424+
impl get_size2::GetSize for FunctionalTypedDictType<'_> {}
425425

426-
impl<'db> SynthesizedTypedDictType<'db> {
426+
impl<'db> FunctionalTypedDictType<'db> {
427427
pub(super) fn apply_type_mapping_impl<'a>(
428428
self,
429429
db: &'db dyn Db,
@@ -442,7 +442,7 @@ impl<'db> SynthesizedTypedDictType<'db> {
442442
})
443443
.collect::<FxOrderMap<_, _>>();
444444

445-
SynthesizedTypedDictType::new(db, self.name(db), self.params(db), items)
445+
FunctionalTypedDictType::new(db, self.name(db), self.params(db), items)
446446
}
447447

448448
pub(crate) fn normalized_impl(
@@ -469,9 +469,9 @@ pub(crate) fn walk_typed_dict_type<'db, V: visitor::TypeVisitor<'db> + ?Sized>(
469469
visitor: &V,
470470
) {
471471
match typed_dict {
472-
TypedDictType::FromClass(class) => visitor.visit_type(db, class.into()),
473-
TypedDictType::Synthesized(synthesized) => {
474-
for (_, item) in synthesized.items(db) {
472+
TypedDictType::ClassBased(class) => visitor.visit_type(db, class.into()),
473+
TypedDictType::Functional(functional) => {
474+
for (_, item) in functional.items(db) {
475475
visitor.visit_type(db, item.declared_ty);
476476
}
477477
}

0 commit comments

Comments
 (0)