Skip to content

Commit 40e0e9f

Browse files
committed
docs
1 parent 0f4b1b0 commit 40e0e9f

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

crates/ty_python_semantic/src/types.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ pub use crate::util::diagnostics::add_inferred_python_version_hint_to_diagnostic
5454
use crate::{Db, FxOrderSet, Module, Program};
5555
pub(crate) use class::{ClassLiteral, ClassType, GenericAlias, KnownClass};
5656
use instance::Protocol;
57-
pub(crate) use instance::{NominalInstanceType, ProtocolInstanceType};
58-
pub(crate) use special_form::SpecialFormType;
57+
pub use instance::{NominalInstanceType, ProtocolInstanceType};
58+
pub use special_form::SpecialFormType;
5959

6060
mod builder;
6161
mod call;
@@ -511,8 +511,12 @@ pub enum Type<'db> {
511511
/// The set of Python objects that conform to the interface described by a given protocol.
512512
/// Construct this variant using the `Type::instance` constructor function.
513513
ProtocolInstance(ProtocolInstanceType<'db>),
514-
/// A single Python object that requires special treatment in the type system
514+
/// A single Python object that requires special treatment in the type system,
515+
/// and which exists at a location that can be known prior to any analysis by ty.
515516
SpecialForm(SpecialFormType),
517+
/// Singleton types that are heavily special-cased by ty, and which are usually
518+
/// created as a result of some runtime operation (e.g. a type-alias statement,
519+
/// a typevar definition, or `Generic[T]` in a class's bases list).
516520
KnownInstance(KnownInstanceType<'db>),
517521
/// An instance of `builtins.property`
518522
PropertyInstance(PropertyInstanceType<'db>),
@@ -5717,15 +5721,17 @@ impl<'db> TypeMapping<'_, 'db> {
57175721
}
57185722
}
57195723

5720-
/// Despite its name, this is quite a different type from `NominalInstanceType`.
5721-
/// For the vast majority of instance-types in Python, we cannot say how many possible
5722-
/// inhabitants there are or could be of that type at runtime. Each variant of the
5723-
/// [`KnownInstanceType`] enum, however, represents a specific runtime symbol
5724-
/// that requires heavy special-casing in the type system. Thus any one `KnownInstance`
5725-
/// variant can only be inhabited by one specific object at runtime.
5724+
/// Singleton types that are heavily special-cased by ty. Despite its name,
5725+
/// quite a different type to [`NominalInstanceType`].
57265726
///
5727-
/// Conceptually this type is quite similar to `SpecialFormType` and has many similar
5728-
/// methods. Unlike that enum, however, this enum's variants are able to wrap associated data.
5727+
/// In many ways, this enum behaves similarly to [`SpecialFormType`].
5728+
/// Unlike instances of that variant, however, `Type::KnownInstance`s do not exist
5729+
/// at a location that can be known prior to any analysis by ty, and each variant
5730+
/// of `KnownInstanceType` can have multiple instances (as, unlike `SpecialFormType`,
5731+
/// `KnownInstanceType` variants can hold associated data). Instances of this type
5732+
/// are generally created by operations at runtime in some way, such as a type alias
5733+
/// statement, a typevar definition, or an instance of `Generic[T]` in a class's
5734+
/// bases list.
57295735
///
57305736
/// # Ordering
57315737
///
@@ -5736,12 +5742,12 @@ impl<'db> TypeMapping<'_, 'db> {
57365742
pub enum KnownInstanceType<'db> {
57375743
/// The type of `Protocol[T]`, `Protocol[U, S]`, etc -- usually only found in a class's bases list.
57385744
///
5739-
/// Note that unsubscripted `Protocol` is represented by [`special_form::SpecialFormType::Protocol`], not this type.
5745+
/// Note that unsubscripted `Protocol` is represented by [`SpecialFormType::Protocol`], not this type.
57405746
SubscriptedProtocol(GenericContext<'db>),
57415747

57425748
/// The type of `Generic[T]`, `Generic[U, S]`, etc -- usually only found in a class's bases list.
57435749
///
5744-
/// Note that unsubscripted `Generic` is represented by [`special_form::SpecialFormType::Generic`], not this type.
5750+
/// Note that unsubscripted `Generic` is represented by [`SpecialFormType::Generic`], not this type.
57455751
SubscriptedGeneric(GenericContext<'db>),
57465752

57475753
/// A single instance of `typing.TypeVar`

crates/ty_python_semantic/src/types/special_form.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ pub enum SpecialFormType {
108108
/// The symbol `typing.Protocol` (which can also be found as `typing_extensions.Protocol`)
109109
///
110110
/// Note that instances of subscripted `typing.Protocol` are not represented by this type;
111-
/// see also [`KnownInstanceType::SubscriptedProtocol`].
111+
/// see also [`super::KnownInstanceType::SubscriptedProtocol`].
112112
Protocol,
113113

114114
/// The symbol `typing.Generic` (which can also be found as `typing_extensions.Generic`).
115115
///
116116
/// Note that instances of subscripted `typing.Generic` are not represented by this type;
117-
/// see also [`KnownInstanceType::SubscriptedGeneric`].
117+
/// see also [`super::KnownInstanceType::SubscriptedGeneric`].
118118
Generic,
119119
}
120120

0 commit comments

Comments
 (0)