[issue26120] pydoc: move __future__ imports out of the DATA block

Irit Katriel report at bugs.python.org
Mon Mar 28 05:51:33 EDT 2022


Irit Katriel <iritkatriel at gmail.com> added the comment:

That's a good point. I see that the __future__ imports appear in the dir() of the module, and indeed they are imported with 'from m import *'. 

But I wonder if that is actually a bug. If you try this:


% cat x.py    

from __future__ import annotations

% cat y.py    
from x import *

print(dir())

class D:
    def f(self, a: D):
        return 42

% ./python.exe y.py    
['__annotations__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'annotations']
Traceback (most recent call last):
  File "/Users/iritkatriel/src/cpython-654/y.py", line 5, in <module>
    class D:
    ^^^^^^^^
  File "/Users/iritkatriel/src/cpython-654/y.py", line 6, in D
    def f(self, a: D):
                   ^
NameError: name 'D' is not defined
--------------------------------------------------


but if you add "from __future__ import annotations" at the top of y.py, then it does run.

So perhaps the future imports should be excluded by "from m import *"?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue26120>
_______________________________________


More information about the Python-bugs-list mailing list