Skip to content
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

Should __all__ itself be included? #6810

Closed
1 of 2 tasks
sobolevn opened this issue Jan 4, 2022 · 5 comments
Closed
1 of 2 tasks

Should __all__ itself be included? #6810

sobolevn opened this issue Jan 4, 2022 · 5 comments
Labels
project: infrastructure typeshed build, test, documentation, or distribution related

Comments

@sobolevn
Copy link
Member

sobolevn commented Jan 4, 2022

Our CONTRIBUTING.md guide says that all names in __all__ should be included. But, should __all__ itself be defined?

I've seen that some modules do have __all__ inside. Some - don't.
It is not related to the original source: some modules with __all__ defined in the source code do not have __all__ defined in stubs. Some are very accurate and even include different versions.

As @srittau said in #5569 it looks inconsistent.

Maybe we should:

  • Add a note to CONTRIBUTING.md about adding __all__ for newly added stubs?
  • Start checking __all__ on modified modules to slowly fix all files?

Refs #1287

@srittau
Copy link
Collaborator

srittau commented Jan 4, 2022

We already have a recommendation to that effect in the Type Stubs document. At some point, we should redirect to that from CONTRIBUTING, but in the meantime, we could just copy that recommendation.

@Avasam
Copy link
Collaborator

Avasam commented Feb 20, 2023

Related question: What should be done when __all__ is wrong? Specifically when it includes a symbol that can't be imported at runtime / doesn't exist. Should the stub omit those entries as a service to stub users? (and add a stubtest allowlist entry for that __all__)

@hauntsaninja
Copy link
Collaborator

You should fix it upstream ;-)

@Avasam
Copy link
Collaborator

Avasam commented May 2, 2023

You should fix it upstream ;-)

Fair, but a decision still has to be taken in the mean time while developping stubs >.<

I think the best is to type-ignore it if stubtest is to flag a difference in __all__. stubtest suppressions are too vague and imo less preferable. And if the fix upstream is to add the missing element, then stubs will already have said element.


Concerning the original question: Doesn't __all__ dictate which elements are imported when doing star-imports? In which case, __all__ should be exactly like the source (absent if absent, present if present) for type-checkers to be accurate. It's also easier to validate with tooling this way.

@srittau srittau added project: infrastructure typeshed build, test, documentation, or distribution related and removed docs labels Mar 23, 2024
@srittau
Copy link
Collaborator

srittau commented Apr 16, 2024

I think there is consensus that __all__ should be included iff it's included in the implementation. There is also already a recommendation to do so in the type stubs style guide at typing.readthedocs.io, so I think we can close this here.

@srittau srittau closed this as completed Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
project: infrastructure typeshed build, test, documentation, or distribution related
Projects
None yet
Development

No branches or pull requests

5 participants