class documentation

class LiteralType(ProperType): (source)

View In Hierarchy

The type of a Literal instance. Literal[Value]

A Literal always consists of:

  1. A native Python object corresponding to the contained inner value
  2. A fallback for this Literal. The fallback also corresponds to the parent type this Literal subtypes.

For example, 'Literal[42]' is represented as 'LiteralType(value=42, fallback=instance_of_int)'

As another example, Literal[Color.RED] (where Color is an enum) is represented as `LiteralType(value="RED", fallback=instance_of_color)'.

Class Method deserialize Undocumented
Method __eq__ Undocumented
Method __hash__ Undocumented
Method __init__ Undocumented
Method accept Undocumented
Method can​_be​_false​_default Undocumented
Method can​_be​_true​_default Undocumented
Method is​_enum​_literal Undocumented
Method serialize Undocumented
Method value​_repr Returns the string representation of the underlying type.
Class Variable __slots__ Undocumented
Instance Variable fallback Undocumented
Instance Variable value Undocumented

Inherited from Type (via ProperType):

Method __repr__ 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
@classmethod
def deserialize(cls, data): (source)

Undocumented

Parameters
data:JsonDictUndocumented
Returns
LiteralTypeUndocumented
def __eq__(self, other): (source)

Undocumented

Parameters
other:objectUndocumented
Returns
boolUndocumented
def __hash__(self): (source)

Undocumented

Returns
intUndocumented
def __init__(self, value, fallback, line=-1, column=-1): (source)

Undocumented

Parameters
value:LiteralValueUndocumented
fallback:InstanceUndocumented
line:intUndocumented
column:intUndocumented
def accept(self, visitor): (source)

Undocumented

Parameters
visitor:TypeVisitor[T]Undocumented
Returns
TUndocumented
def can_be_false_default(self): (source)

Undocumented

Returns
boolUndocumented
def can_be_true_default(self): (source)

Undocumented

Returns
boolUndocumented
def is_enum_literal(self): (source)

Undocumented

Returns
boolUndocumented
def serialize(self): (source)

Undocumented

Returns
Union[JsonDict, str]Undocumented
def value_repr(self): (source)

Returns the string representation of the underlying type.

This function is almost equivalent to running repr(self.value), except it includes some additional logic to correctly handle cases where the value is a string, byte string, a unicode string, or an enum.

Returns
strUndocumented
__slots__: tuple[str, ...] = (source)

Undocumented

fallback = (source)

Undocumented

value = (source)

Undocumented