If you have a __future__ import in a script, and you import * from it in
another script, the object for this future appears in the dir() of the other
script, even though the __future__ import has no effect there.
% 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
I think we should change import * to exclude the __future__ import objects, and
perhaps also to not show them in dir(x). Any objections?
This came up in the discussion about https://bugs.python.org/issue26120 . See
the attached PR for a technique we can use to identify those objects.
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/3BUUCY2OHZILBJLOTS6I33M5YW4INDW3/
Code of Conduct: http://python.org/psf/codeofconduct/