-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
__text_signature__ parser doesn't handle globals in extension module #82062
Comments
Starting from the custom2 example at https://docs.python.org/3/extending/newtypes_tutorial.html#adding-data-and-methods-to-the-basic-example, change the methods table to
and add a global ONE to the module dict: PyModule_AddObject(m, "ONE", PyLong_FromLong(1)); Building and running e.g. pydoc on this module results in Traceback (most recent call last):
File ".../lib/python3.7/inspect.py", line 2003, in wrap_value
value = eval(s, module_dict)
File "<string>", line 1, in <module>
NameError: name 'ONE' is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".../lib/python3.7/inspect.py", line 2006, in wrap_value
value = eval(s, sys_module_dict)
File "<string>", line 1, in <module>
NameError: name 'ONE' is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".../lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
<elided>
File ".../lib/python3.7/inspect.py", line 2008, in wrap_value
raise RuntimeError()
RuntimeError I think the fix is fairly simple; one needs to replace module_name = getattr(obj, '__module__', None) in inspect.py::_signature_fromstr by module_name = (getattr(obj, '__module__', None)
or getattr(getattr(obj, '__objclass__'), '__module__', None)) (This is a less general but simpler solution than https://bugs.python.org/issue23967.) |
… inspect.signature() The ``__module__`` attribute is missing for instance methods in extension modules, so instead we use in this case ``__objclass__.__module__``.
… inspect.signature()
…odules (GH-115270) Now inspect.signature() supports references to the module globals in parameter defaults on methods in extension modules. Previously it was only supported in functions. The workaround was to specify the fully qualified name, including the module name.
…sion modules (pythonGH-115270) Now inspect.signature() supports references to the module globals in parameter defaults on methods in extension modules. Previously it was only supported in functions. The workaround was to specify the fully qualified name, including the module name.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: