MCPcopy
hub / github.com/python/mypy / numeric_type

Method numeric_type

mypy/fastparse.py:2079–2095  ·  view source on GitHub ↗
(self, value: object, n: AST)

Source from the content-addressed store, hash-verified

2077 return self.invalid_type(n)
2078
2079 def numeric_type(self, value: object, n: AST) -> Type:
2080 # The node's field has the type complex, but complex isn't *really*
2081 # a parent of int and float, and this causes isinstance below
2082 # to think that the complex branch is always picked. Avoid
2083 # this by throwing away the type.
2084 if isinstance(value, int):
2085 numeric_value: int | None = value
2086 type_name = "builtins.int"
2087 else:
2088 # Other kinds of numbers (floats, complex) are not valid parameters for
2089 # RawExpressionType so we just pass in 'None' for now. We'll report the
2090 # appropriate error at a later stage.
2091 numeric_value = None
2092 type_name = f"builtins.{type(value).__name__}"
2093 return RawExpressionType(
2094 numeric_value, type_name, line=self.line, column=getattr(n, "col_offset", -1)
2095 )
2096
2097 def visit_Slice(self, n: ast3.Slice) -> Type:
2098 return self.invalid_type(n, note="did you mean to use ',' instead of ':' ?")

Callers 1

visit_ConstantMethod · 0.95

Calls 4

RawExpressionTypeClass · 0.90
isinstanceFunction · 0.85
typeClass · 0.85
getattrFunction · 0.85

Tested by

no test coverage detected