Skip to content
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

DeprecationWarning: builtin type X has no __module__ attribute #1298

Closed
davidhewitt opened this issue Nov 28, 2020 · 6 comments · Fixed by #1343
Closed

DeprecationWarning: builtin type X has no __module__ attribute #1298

davidhewitt opened this issue Nov 28, 2020 · 6 comments · Fixed by #1343
Assignees
Labels

Comments

@davidhewitt
Copy link
Member

On Python 3.7 and up I see warnings of the following form when running the pyo3 test suite:

DeprecationWarning: builtin type X has no __module__ attribute

I think this is probably related to using a #[pyclass] when not adding it to a module. I haven't investigated yet.

Example test which demonstrates this issue:

$ cargo test --test test_various return_custom_class
    Finished test [unoptimized + debuginfo] target(s) in 0.03s
     Running target/debug/deps/test_various-a73ba5b7affaefde

running 1 test
<string>:1: DeprecationWarning: builtin type PyUsize has no __module__ attribute
test return_custom_class ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 7 filtered out

I'm not sure what changes we need to make to resolve.

@ChillFish8
Copy link

ChillFish8 commented Nov 28, 2020

I think this is probably related to using a #[pyclass] when not adding it to a module. I haven't investigated yet.

This does seem to be the trend with the issue when re-producing, when exposed to the module this error goes away. Only when you dont expose it directly does this warning get raised from my findings

@bderrett
Copy link

bderrett commented Dec 27, 2020

This appears to cause an error when running doctests:

$ python -m doctest -v myfile.py
Traceback (most recent call last):
  File "/home/ben/miniconda3/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/ben/miniconda3/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/ben/miniconda3/lib/python3.8/doctest.py", line 2793, in <module>
    sys.exit(_test())
  File "/home/ben/miniconda3/lib/python3.8/doctest.py", line 2783, in _test
    failures, _ = testmod(m, verbose=verbose, optionflags=options)
  File "/home/ben/miniconda3/lib/python3.8/doctest.py", line 1955, in testmod
    for test in finder.find(m, name, globs=globs, extraglobs=extraglobs):
  File "/home/ben/miniconda3/lib/python3.8/doctest.py", line 939, in find
    self._find(tests, obj, name, module, source_lines, globs, {})
  File "/home/ben/miniconda3/lib/python3.8/doctest.py", line 1000, in _find
    self._from_module(module, val)):
  File "/home/ben/miniconda3/lib/python3.8/doctest.py", line 967, in _from_module
    return module.__name__ == object.__module__
AttributeError: __module__

It can be worked around by setting MyPyClass.__module__ = None.

@bderrett
Copy link

"__module__ is the name of the module the function was defined in or None if unavailable" https://docs.python.org/3/reference/datamodel.html

So perhaps the __module__ attribute should be set to None if the pyclass is not added to a module?

@davidhewitt
Copy link
Member Author

That sounds like a valid solution, though it's not super clear how to do that correctly with PyType_FromSpec. I'll keep playing with it and see if I can get it right.

@davidhewitt
Copy link
Member Author

@bderrett am I right in thinking this is a new regression for PyO3 0.13? It's quite possibly related to the abi3 work / switch to heap types.

@bderrett
Copy link

@davidhewitt Yes. A bisection shows that it was introduced when the "PyO3/abi3" branch was merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants