-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
stubgen: include __all__ in output #16356
Changes from 1 commit
f03f12c
b545d45
59e4415
cc37d9e
f8d5c55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -587,20 +587,26 @@ __all__ = [] + ['f'] | |
def f(): ... | ||
def g(): ... | ||
[out] | ||
__all__ = ['f'] | ||
|
||
def f() -> None: ... | ||
|
||
[case testOmitDefsNotInAll_semanal] | ||
__all__ = ['f'] | ||
def f(): ... | ||
def g(): ... | ||
[out] | ||
__all__ = ['f'] | ||
|
||
def f() -> None: ... | ||
|
||
[case testOmitDefsNotInAll_inspect] | ||
__all__ = [] + ['f'] | ||
def f(): ... | ||
def g(): ... | ||
[out] | ||
__all__ = ['f'] | ||
|
||
def f(): ... | ||
|
||
[case testVarDefsNotInAll_import] | ||
|
@@ -610,6 +616,8 @@ x = 1 | |
y = 1 | ||
def g(): ... | ||
[out] | ||
__all__ = ['f', 'g'] | ||
|
||
def f() -> None: ... | ||
def g() -> None: ... | ||
|
||
|
@@ -620,6 +628,8 @@ x = 1 | |
y = 1 | ||
def g(): ... | ||
[out] | ||
__all__ = ['f', 'g'] | ||
|
||
def f(): ... | ||
def g(): ... | ||
|
||
|
@@ -628,6 +638,8 @@ __all__ = [] + ['f'] | |
def f(): ... | ||
class A: ... | ||
[out] | ||
__all__ = ['f'] | ||
|
||
def f() -> None: ... | ||
|
||
class A: ... | ||
|
@@ -637,6 +649,8 @@ __all__ = [] + ['f'] | |
def f(): ... | ||
class A: ... | ||
[out] | ||
__all__ = ['f'] | ||
|
||
def f(): ... | ||
|
||
class A: ... | ||
|
@@ -647,6 +661,8 @@ class A: | |
x = 1 | ||
def f(self): ... | ||
[out] | ||
__all__ = ['A'] | ||
|
||
class A: | ||
x: int | ||
def f(self) -> None: ... | ||
|
@@ -684,6 +700,8 @@ x = 1 | |
[out] | ||
from re import match as match, sub as sub | ||
|
||
__all__ = ['match', 'sub', 'x'] | ||
|
||
x: int | ||
|
||
[case testExportModule_import] | ||
|
@@ -694,6 +712,8 @@ y = 2 | |
[out] | ||
import re as re | ||
|
||
__all__ = ['re', 'x'] | ||
|
||
x: int | ||
|
||
[case testExportModule2_import] | ||
|
@@ -704,6 +724,8 @@ y = 2 | |
[out] | ||
import re as re | ||
|
||
__all__ = ['re', 'x'] | ||
|
||
x: int | ||
|
||
[case testExportModuleAs_import] | ||
|
@@ -714,6 +736,8 @@ y = 2 | |
[out] | ||
import re as rex | ||
|
||
__all__ = ['rex', 'x'] | ||
|
||
x: int | ||
|
||
[case testExportModuleInPackage_import] | ||
|
@@ -722,13 +746,17 @@ __all__ = ['p'] | |
[out] | ||
import urllib.parse as p | ||
|
||
__all__ = ['p'] | ||
|
||
[case testExportPackageOfAModule_import] | ||
import urllib.parse | ||
__all__ = ['urllib'] | ||
|
||
[out] | ||
import urllib as urllib | ||
|
||
__all__ = ['urllib'] | ||
|
||
[case testRelativeImportAll] | ||
from .x import * | ||
[out] | ||
|
@@ -741,6 +769,8 @@ x = 1 | |
class C: | ||
def g(self): ... | ||
[out] | ||
__all__ = ['f', 'x', 'C', 'g'] | ||
|
||
def f() -> None: ... | ||
|
||
x: int | ||
|
@@ -758,6 +788,8 @@ x = 1 | |
class C: | ||
def g(self): ... | ||
[out] | ||
__all__ = ['f', 'x', 'C', 'g'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. Maybe it's problematic if stubgen adds There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's probably better to omit the undefined names so the generated stub won't create errors for type checkers, so I pushed that change. Could go either way though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (For future readers of this thread: we decided to go back on this; see the discussion in #16356 (comment) for why) |
||
|
||
def f(): ... | ||
|
||
x: int | ||
|
@@ -2343,6 +2375,8 @@ else: | |
[out] | ||
import cookielib as cookielib | ||
|
||
__all__ = ['cookielib'] | ||
|
||
[case testCannotCalculateMRO_semanal] | ||
class X: pass | ||
|
||
|
@@ -2788,6 +2822,8 @@ class A: pass | |
# p/__init__.pyi | ||
from p.a import A | ||
|
||
__all__ = ['a'] | ||
|
||
a: A | ||
# p/a.pyi | ||
class A: ... | ||
|
@@ -2963,6 +2999,8 @@ __version__ = '' | |
[out] | ||
from m import __version__ as __version__ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a problem before your PR, but I'm not sure what the justification is for not importing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, they're in IGNORED_DUNDERS in stubutil.py. It generally makes sense to exclude these names as they're not useful in stubs, but we shouldn't ignore them if they're in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pushed a change so that IGNORED_DUNDERS aren't ignored if they're in |
||
|
||
__all__ = ['__about__', '__author__', '__version__'] | ||
|
||
[case testAttrsClass_semanal] | ||
import attrs | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kinda cool that stubgen has sophisticated enough inference to do this. Didn't realise that it had this capability!