class documentation

Internal implementation of libstatic.Type.

Method __hash__ Undocumented
Method __str__ Undocumented
Method add_args Get a copy of the Type with the given args added in the list of args.
Method add_meta Get a copy of the Type with the given meta informations updated.
Method get_meta Undocumented
Method merge Get a union of the two given types.
Method supertype_of Undocumented
Class Variable Any Undocumented
Class Variable Callable Undocumented
Class Variable Literal Undocumented
Class Variable ModuleType Undocumented
Class Variable Optional Undocumented
Class Variable overload Undocumented
Class Variable TypeType Undocumented
Class Variable Union Undocumented
Instance Variable __dict__ Undocumented
Instance Variable args Arguments of a generic type if any.
Instance Variable meta Stores meta information when the type annotations are not expressive enougth. Used for intermediate inference steps.
Instance Variable name The name of the type.
Instance Variable scope The scope where the type is defined. This is often a module, but it migth be a class or a function in some cases.
Property annotation Represent the type as a string suitable for type annotations.
Property definition Undocumented
Property is_callable Undocumented
Property is_literal A literal type means it's literal values can be recovered with:
Property is_module Undocumented
Property is_none Undocumented
Property is_optional Undocumented
Property is_overload No summary
Property is_protocol Undocumented
Property is_type Undocumented
Property is_typevar Undocumented
Property is_union Undocumented
Property location Undocumented
Property long_annotation Like annotation but returns the type with qualified names.
Property qualname The full name of the type.
Property supertype Undocumented
Property unknown Undocumented
Method _replace Undocumented
def __hash__(self) -> int: (source)

Undocumented

def __str__(self) -> str: (source)

Undocumented

def add_args(self, args: Iterable[Type]) -> Type: (source)

Get a copy of the Type with the given args added in the list of args.

def add_meta(self, **meta: object) -> Type: (source)

Get a copy of the Type with the given meta informations updated.

@overload
def get_meta(self, key: Lit[definition]) -> Def | None:
@overload
def get_meta(self, key: Lit[location]) -> NodeLocation | None:
@overload
def get_meta(self, key: Lit[members]) -> Mapping[str, Type] | None:
@overload
def get_meta(self, key: Lit[mro]) -> Sequence[Type] | None:
@overload
def get_meta(self, key: Lit[unknown]) -> bool | None:
@overload
def get_meta(self, key: Lit[is_protocol]) -> bool | None:
@overload
def get_meta(self, key: Lit[keyword]) -> str | None:
(source)

Undocumented

def merge(self, other: Type) -> Type: (source)

Get a union of the two given types.

If any of the types is unknown, the other is returned. When possible, the type is simplified. For instance, int | int will be simplified to just int.

def supertype_of(self, other: Type) -> bool: (source)

Undocumented

Undocumented

Undocumented

Undocumented

Undocumented

Undocumented

Undocumented

Undocumented

Undocumented

__dict__: dict = (source)

Undocumented

Arguments of a generic type if any.

For example, (str, int) if the type is dict[str, int].

Stores meta information when the type annotations are not expressive enougth. Used for intermediate inference steps.

The name of the type.

For example, Iterable or list.

The scope where the type is defined. This is often a module, but it migth be a class or a function in some cases.

For example, typing if the type is Iterable. Empty string for built-ins or other special cases.

@property
@lru_cache(maxsize=None)
annotation: str = (source)

Represent the type as a string suitable for type annotations.

The string is a valid Python 3.10 expression. For example, str | dict[str, Any].

@property
definition: Def | None = (source)

Undocumented

Undocumented

A literal type means it's literal values can be recovered with:

>>> type = Type.Literal.add_args(args=[Type('"val"')])
>>> ast.literal_eval(type.args[0].name)
'val'

Undocumented

Undocumented

Undocumented

>>> t = Type.overload.add_args(args=[Type.Callable.add_args([Type('int', 'builtins'), Type('int', 'builtins'),]),
... Type.Callable.add_args([Type('str', 'builtins'), Type('str', 'builtins'),])])
>>> print(t.annotation)
(int) -> int | (str) -> str
>>> assert t.is_overload

Undocumented

Undocumented

Undocumented

Undocumented

@property
location: NodeLocation | None = (source)

Undocumented

@property
@lru_cache(maxsize=None)
long_annotation: str = (source)

Like annotation but returns the type with qualified names.

The full name of the type.

For example, typing.Iterable or builtins.list.

Undocumented

Undocumented

def _replace(self, **changes: str | Sequence[Type] | NodeLocation | dict) -> Type: (source)

Undocumented