MCPcopy Create free account
hub / github.com/rthalley/dnspython / constify

Function constify

dns/immutable.py:49–68  ·  view source on GitHub ↗

Convert mutable types to immutable types.

(o: Any)

Source from the content-addressed store, hash-verified

47
48
49def constify(o: Any) -> Any:
50 """
51 Convert mutable types to immutable types.
52 """
53 if isinstance(o, bytearray):
54 return bytes(o)
55 if isinstance(o, tuple):
56 try:
57 hash(o)
58 return o
59 except Exception:
60 return tuple(constify(elt) for elt in o)
61 if isinstance(o, list):
62 return tuple(constify(elt) for elt in o)
63 if isinstance(o, dict):
64 cdict = dict()
65 for k, v in o.items():
66 cdict[k] = constify(v)
67 return Dict(cdict, True)
68 return o

Callers

nothing calls this directly

Calls 2

DictClass · 0.85
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…