MCPcopy
hub / github.com/pydantic/pydantic / get_module_ns_of

Function get_module_ns_of

pydantic/_internal/_namespace_utils.py:48–61  ·  view source on GitHub ↗

Get the namespace of the module where the object is defined. Caution: this function does not return a copy of the module namespace, so the result should not be mutated. The burden of enforcing this is on the caller.

(obj: Any)

Source from the content-addressed store, hash-verified

46
47
48def get_module_ns_of(obj: Any) -> dict[str, Any]:
49 """Get the namespace of the module where the object is defined.
50
51 Caution: this function does not return a copy of the module namespace, so the result
52 should not be mutated. The burden of enforcing this is on the caller.
53 """
54 module_name = getattr(obj, '__module__', None)
55 if module_name:
56 try:
57 return sys.modules[module_name].__dict__
58 except KeyError:
59 # happens occasionally, see https://github.com/pydantic/pydantic/issues/2363
60 return {}
61 return {}
62
63
64# Note that this class is almost identical to `collections.ChainMap`, but need to enforce

Callers 3

get_function_type_hintsFunction · 0.85
ns_for_functionFunction · 0.85
types_namespaceMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected