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

Method visit_UnaryOp

mypy/fastparse.py:2063–2077  ·  view source on GitHub ↗
(self, n: UnaryOp)

Source from the content-addressed store, hash-verified

2061
2062 # UnaryOp(op, operand)
2063 def visit_UnaryOp(self, n: UnaryOp) -> Type:
2064 # We support specifically Literal[-4], Literal[+4], and nothing else.
2065 # For example, Literal[~6] or Literal[not False] is not supported.
2066 typ = self.visit(n.operand)
2067 if (
2068 isinstance(typ, RawExpressionType)
2069 # Use type() because we do not want to allow bools.
2070 and type(typ.literal_value) is int
2071 ):
2072 if isinstance(n.op, USub):
2073 typ.literal_value *= -1
2074 return typ
2075 if isinstance(n.op, UAdd):
2076 return typ
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*

Callers

nothing calls this directly

Calls 4

visitMethod · 0.95
invalid_typeMethod · 0.95
isinstanceFunction · 0.85
typeClass · 0.85

Tested by

no test coverage detected