class Type(_BaseType): (source)
Known subclasses: libstatic._analyzer.typeinfer.TypeVariable
Internal implementation of libstatic.Type.
| Method | __hash__ |
Undocumented |
| Method | __str__ |
Undocumented |
| Method | add |
Get a copy of the Type with the given args added in the list of args. |
| Method | add |
Get a copy of the Type with the given meta informations updated. |
| Method | get |
Undocumented |
| Method | merge |
Get a union of the two given types. |
| Method | supertype |
Undocumented |
| Class Variable | |
Undocumented |
| Class Variable | |
Undocumented |
| Class Variable | |
Undocumented |
| Class Variable | |
Undocumented |
| Class Variable | |
Undocumented |
| Class Variable | overload |
Undocumented |
| Class Variable | |
Undocumented |
| Class Variable | |
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 |
Undocumented |
| Property | is |
A literal type means it's literal values can be recovered with: |
| Property | is |
Undocumented |
| Property | is |
Undocumented |
| Property | is |
Undocumented |
| Property | is |
No summary |
| Property | is |
Undocumented |
| Property | is |
Undocumented |
| Property | is |
Undocumented |
| Property | is |
Undocumented |
| Property | location |
Undocumented |
| Property | long |
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 |
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.
libstatic.Type.argsArguments 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.
libstatic.Type.annotationRepresent the type as a string suitable for type annotations.
The string is a valid Python 3.10 expression. For example, str | dict[str, Any].
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'
>>> 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
libstatic.Type.qualnameThe full name of the type.
For example, typing.Iterable or builtins.list.