MCPcopy Index your code
hub / github.com/python/mypy / visit_Constant

Method visit_Constant

mypy/fastparse.py:2041–2060  ·  view source on GitHub ↗
(self, n: ast3.Constant)

Source from the content-addressed store, hash-verified

2039 )
2040
2041 def visit_Constant(self, n: ast3.Constant) -> Type:
2042 val = n.value
2043 if val is None:
2044 # None is a type.
2045 return UnboundType("None", line=self.line)
2046 if isinstance(val, str):
2047 # Parse forward reference.
2048 return parse_type_string(val, "builtins.str", self.line, n.col_offset)
2049 if val is Ellipsis:
2050 # '...' is valid in some types.
2051 return EllipsisType(line=self.line)
2052 if isinstance(val, bool):
2053 # Special case for True/False.
2054 return RawExpressionType(val, "builtins.bool", line=self.line)
2055 if isinstance(val, (int, float, complex)):
2056 return self.numeric_type(val, n)
2057 if isinstance(val, bytes):
2058 contents = bytes_to_human_readable_repr(val)
2059 return RawExpressionType(contents, "builtins.bytes", self.line, column=n.col_offset)
2060 # Everything else is invalid.
2061
2062 # UnaryOp(op, operand)
2063 def visit_UnaryOp(self, n: UnaryOp) -> Type:

Callers

nothing calls this directly

Calls 7

numeric_typeMethod · 0.95
UnboundTypeClass · 0.90
EllipsisTypeClass · 0.90
RawExpressionTypeClass · 0.90
isinstanceFunction · 0.85
parse_type_stringFunction · 0.85

Tested by

no test coverage detected