python / python/mypy

Should __init__.py imports be treated as exports with --no-implicit-reexport behaviour?

Open
#10,198 13 comments 17 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature topic-implicit-reexport
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

I'm uncertain whether --no-implicit-reexport has a "correct" behaviour when it comes to __init.py__ files.

If I have this __init__.py file:

from .mysub import MyName

My intent is to export MyName from the module. Currently this does not work however, and I need to do either:

from .mysub import MyName as MyName

or

from .mysub import MyName
__all__ = ['MyName']

Both of which are redundant.

I saw this issue on stub-generation that seems to imply that imports in an init (or otherwise unused imports) should be considered exports.

Shouldn't --no-implicit-reexport treat init files as doing exports for the module without the code having to use the redundant ...as... or __all__ form?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no repository files or tests. Start by locating the implementation and tests for --no-implicit-reexport, then review the linked stub-generation issue and the init.py examples; done means establishing and implementing a decided rule for whether such imports are exports without redundant syntax.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.