class RawExpressionType(ProperType): (source)
A synthetic type representing some arbitrary expression that does not cleanly translate into a type.
This synthetic type is only used at the beginning stages of semantic analysis and should be completely removing during the process for mapping UnboundTypes to actual types: we either turn it into a LiteralType or an AnyType.
For example, suppose Foo[1]
is initially represented as the following:
- UnboundType(
name='Foo', args=[
RawExpressionType(value=1, base_type_name='builtins.int'),],
)
As we perform semantic analysis, this type will transform into one of two possible forms.
If 'Foo' was an alias for 'Literal' all along, this type is transformed into:
LiteralType(value=1, fallback=int_instance_here)
Alternatively, if 'Foo' is an unrelated class, we report an error and instead produce something like this:
Instance(type=typeinfo_for_foo, args=[AnyType(TypeOfAny.from_error))
If the "note" field is not None, the provided note will be reported alongside the error at this point.
Note: if "literal_value" is None, that means this object is representing some expression that cannot possibly be a parameter of Literal[...]. For example, "Foo[3j]" would be represented as:
- UnboundType(
name='Foo', args=[
RawExpressionType(value=None, base_type_name='builtins.complex'),],
)
Method | __eq__ |
Undocumented |
Method | __hash__ |
Undocumented |
Method | __init__ |
Undocumented |
Method | accept |
Undocumented |
Method | serialize |
Undocumented |
Method | simple_name |
Undocumented |
Class Variable | __slots__ |
Undocumented |
Instance Variable | base_type_name |
Undocumented |
Instance Variable | literal_value |
Undocumented |
Instance Variable | note |
Undocumented |
Inherited from Type
(via ProperType
):
Class Method | deserialize |
Undocumented |
Method | __repr__ |
Undocumented |
Method | can_be_false_default |
Undocumented |
Method | can_be_true_default |
Undocumented |
Instance Variable | can_be_false |
Undocumented |
Instance Variable | can_be_true |
Undocumented |
Inherited from Context
(via ProperType
, Type
):
Method | get_column |
Don't use. Use x.column. |
Method | get_line |
Don't use. Use x.line. |
Method | set_line |
If target is a node, pull line (and column) information into this node. If column is specified, this will override any column information coming from a node. |
Instance Variable | column |
Undocumented |
Instance Variable | end_line |
Undocumented |
Instance Variable | line |
Undocumented |
mypy.types.Type.__init__
Undocumented
Parameters | |
literal_value:Optional[ | Undocumented |
base_type_name:str | Undocumented |
line:int | Undocumented |
column:int | Undocumented |
note:Optional[ | Undocumented |
mypy.types.Type.accept
Undocumented
Parameters | |
visitor:TypeVisitor[ | Undocumented |
Returns | |
T | Undocumented |