Issue 26120: pydoc: move future imports out of the DATA block (original) (raw)

It's like this:

import foo dir(foo) ['builtins', 'cached', 'doc', 'file', 'loader', 'name', 'package', 'spec', 'annotations', 'x'] foo.annotations _Feature((3, 7, 0, 'beta', 1), (3, 11, 0, 'alpha', 0), 16777216)

So the attribute in foo is called annotations, i.e. it's not private.

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 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 *"?

Yet one bug: PR 30888 only changed the text output. But there is also the html output generator.

I'm not sure - if I revert the change like this:

     if isinstance(getattr(obj, name, None), __future__._Feature):

then test_html_doc fails:

====================================================================== FAIL: test_html_doc (test.test_pydoc.PydocDocTest.test_html_doc)

Traceback (most recent call last): File "/Users/iritkatriel/src/cpython/Lib/test/test_pydoc.py", line 414, in test_html_doc self.assertEqual(text_lines, expected_lines) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AssertionError: Lists differ: ['tes[1392 chars]t]', "print_function = _Feature((2, 6, 0, 'alp[156 chars]ody'] != ['tes[1392 chars]t]', 'type_union1 = typing.Union[int, str]', '[72 chars]ody']

First differing element 55: "print_function = _Feature((2, 6, 0, 'alp[36 chars]576)" 'type_union1 = typing.Union[int, str]'

First list contains 1 additional elements. First extra element 61: 'Nobody'

['test.pydoc_mod (version 1.2.3.4)', 'This is a test module for test_pydoc', 'Modules', 'types', 'typing', 'Classes', 'builtins.object', 'A', 'B', 'C', 'class A(builtins.object)', 'Hello and goodbye', 'Methods defined here:', 'init()', 'Wow, I have no function!', 'Data descriptors defined here:', 'dict', 'dictionary for instance variables (if defined)', 'weakref', 'list of weak references to the object (if defined)', 'class B(builtins.object)', 'Data descriptors defined here:', 'dict', 'dictionary for instance variables (if defined)', 'weakref', 'list of weak references to the object (if defined)', 'Data and other attributes defined here:', "NO_MEANING = 'eggs'", "annotations = {'NO_MEANING': <class 'str'>}", 'class C(builtins.object)', 'Methods defined here:', 'get_answer(self)', 'Return say_no()', 'is_it_true(self)', 'Return self.get_answer()', 'say_no(self)', 'Class methods defined here:', 'class_getitem(item) from builtins.type', 'Data descriptors defined here:', 'dict', 'dictionary for instance variables (if defined)', 'weakref', 'list of weak references to the object (if defined)', 'Functions', 'doc_func()', "This function solves all of the world's problems:", 'hunger', 'lack of Python', 'war', 'nodoc_func()', 'Data', "xyz = 'X, Y and Z'", 'c_alias = test.pydoc_mod.C[int]', 'list_alias1 = typing.List[int]', 'list_alias2 = list[int]',