On Mon, Mar 28, 2022 at 6:29 AM Irit Katriel via Python-Dev <
python-dev@python.org> wrote:

> 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.
>

"Future" imports are special to the parser, and they may also set a flag
for the runtime to alter its behavior, but they are intentionally not
treated specially by code generation, so they are still properly imported.
However the presence of the imported thing is not used by the runtime to
determine its behavior; those flags are stored elsewhere guided by the code
generator.

I don't think there's anything to do here.

-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/GRZFVFLEGSXHLUHWHEV75AMMBCEJLVUE/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to