Fix logging from mangled methods where class name starts with "_"

Python's name-mangling rules are quite complex. Previously, EDMC was
incorrectly mangling names where the class name starts with one or more
underscores; if the class name starts with any underscores, they should
be removed before prepending to the identifier being mangled. If the
class name contains *only* underscores, no mangling should be performed.
This commit is contained in:
Ash Holland authored and Athanasius committed 2021-01-08 15:32:42 +00:00
1 parent 5776149d5d
commit 590cd608d3
1 file changed
+4 -2
+4 -2
View File
@@ -309,9 +309,11 @@ class EDMCContextFilter(logging.Filter):
if frame_class:
# See https://en.wikipedia.org/wiki/Name_mangling#Python for how name mangling works.
# For more detail, see _Py_Mangle in CPython's Python/compile.c.
name = frame_info.function
if name.startswith("__") and not name.endswith("__"):
name = f'_{frame_class.__class__.__name__}{frame_info.function}'
class_name = frame_class.__class__.__name__.lstrip("_")
if name.startswith("__") and not name.endswith("__") and class_name:
name = f'_{class_name}{frame_info.function}'
# Find __qualname__ of the caller
fn = inspect.getattr_static(frame_class, name, None)