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 |
The location of the node that defined this type. It's set to an unknown location by default so special types can be created dynamically. |
| Instance Variable | meta |
The type symbol definition, if it has one. Can be None for builtins (if the builtins module is not in the system) and other special cases like Callable or Unions. |
| 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.argsThe location of the node that defined this type. It's set to an unknown location by default so special types can be created dynamically.
The type symbol definition, if it has one. Can be None for builtins (if the builtins module is not in the system) and other special cases like Callable or Unions.
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.