MCPcopy
hub / github.com/python-trio/trio / fix_one

Function fix_one

src/trio/_util.py:205–224  ·  view source on GitHub ↗
(qualname: str, name: str, obj: object)

Source from the content-addressed store, hash-verified

203 seen_ids: set[int] = set()
204
205 def fix_one(qualname: str, name: str, obj: object) -> None:
206 # avoid infinite recursion (relevant when using
207 # typing.Generic, for example)
208 if id(obj) in seen_ids:
209 return
210 seen_ids.add(id(obj))
211
212 mod = getattr(obj, "__module__", None)
213 if mod is not None and mod.startswith("trio."):
214 obj.__module__ = module_name
215 # Modules, unlike everything else in Python, put fully-qualified
216 # names into their __name__ attribute. We check for "." to avoid
217 # rewriting these.
218 if hasattr(obj, "__name__") and "." not in obj.__name__:
219 obj.__name__ = name
220 if hasattr(obj, "__qualname__"):
221 obj.__qualname__ = qualname
222 if isinstance(obj, type):
223 for attr_name, attr_value in obj.__dict__.items():
224 fix_one(objname + "." + attr_name, attr_name, attr_value)
225
226 for objname, obj in namespace.items():
227 if not objname.startswith("_"): # ignore private attributes

Callers 1

fixup_module_metadataFunction · 0.85

Calls 1

addMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…