MCPcopy Create free account
hub / github.com/python/mypy / is_valid_replacement

Function is_valid_replacement

mypy/semanal.py:8341–8355  ·  view source on GitHub ↗

Can symbol table node replace an existing one? These are the only valid cases: 1. Placeholder gets replaced with a non-placeholder 2. Placeholder that isn't known to become type replaced with a placeholder that can become a type

(old: SymbolTableNode, new: SymbolTableNode)

Source from the content-addressed store, hash-verified

8339
8340
8341def is_valid_replacement(old: SymbolTableNode, new: SymbolTableNode) -> bool:
8342 """Can symbol table node replace an existing one?
8343
8344 These are the only valid cases:
8345
8346 1. Placeholder gets replaced with a non-placeholder
8347 2. Placeholder that isn't known to become type replaced with a
8348 placeholder that can become a type
8349 """
8350 if isinstance(old.node, PlaceholderNode):
8351 if isinstance(new.node, PlaceholderNode):
8352 return not old.node.becomes_typeinfo and new.node.becomes_typeinfo
8353 else:
8354 return True
8355 return False
8356
8357
8358def is_same_symbol(a: SymbolNode | None, b: SymbolNode | None) -> bool:

Callers 1

add_symbol_table_nodeMethod · 0.85

Calls 1

isinstanceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…