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

Function literal_hash

mypy/literals.py:103–115  ·  view source on GitHub ↗

Generate a hashable, (mostly) opaque key for expressions supported by the binder. These allow using expressions as dictionary keys based on structural/value matching (instead of based on expression identity). Return None if the expression type is not supported (it cannot be narrowed).

(e: Expression)

Source from the content-addressed store, hash-verified

101
102
103def literal_hash(e: Expression) -> Key | None:
104 """Generate a hashable, (mostly) opaque key for expressions supported by the binder.
105
106 These allow using expressions as dictionary keys based on structural/value
107 matching (instead of based on expression identity).
108
109 Return None if the expression type is not supported (it cannot be narrowed).
110
111 See the comment above for more information.
112
113 NOTE: This is not directly related to literal types.
114 """
115 return e.accept(_hasher)
116
117
118def literal(e: Expression) -> int:

Callers 15

check_func_defMethod · 0.90
and_conditional_mapsFunction · 0.90
or_conditional_mapsFunction · 0.90
update_type_mapMethod · 0.90
putMethod · 0.90
getMethod · 0.90
cleanseMethod · 0.90
literalFunction · 0.85
visit_star_exprMethod · 0.85

Calls 1

acceptMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…