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

Method put

mypy/binder.py:250–264  ·  view source on GitHub ↗

Directly set the narrowed type of expression (if it supports it). This is used for isinstance() etc. Assignments should go through assign_type().

(self, expr: Expression, typ: Type, *, from_assignment: bool = True)

Source from the content-addressed store, hash-verified

248 return isinstance(expr, (IndexExpr, MemberExpr, NameExpr)) and literal(expr) > LITERAL_NO
249
250 def put(self, expr: Expression, typ: Type, *, from_assignment: bool = True) -> None:
251 """Directly set the narrowed type of expression (if it supports it).
252
253 This is used for isinstance() etc. Assignments should go through assign_type().
254 """
255 if not isinstance(expr, (IndexExpr, MemberExpr, NameExpr)):
256 return
257 if not literal(expr):
258 return
259 key = literal_hash(expr)
260 assert key is not None, "Internal error: binder tried to put non-literal"
261 if key not in self.declarations:
262 self.declarations[key] = get_declaration(expr)
263 self._add_dependencies(key)
264 self._put(key, typ, from_assignment)
265
266 def unreachable(self) -> None:
267 self.version += 1

Callers 9

assign_typeMethod · 0.95
check_func_defMethod · 0.80
check_assignmentMethod · 0.80
push_type_mapMethod · 0.80
workerFunction · 0.80
serverFunction · 0.80

Calls 6

_add_dependenciesMethod · 0.95
_putMethod · 0.95
literalFunction · 0.90
literal_hashFunction · 0.90
isinstanceFunction · 0.85
get_declarationFunction · 0.85

Tested by 2

serverFunction · 0.64