Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Import all submodules into module #525

Open
kevihiiin opened this issue May 24, 2020 · 1 comment
Open

Import all submodules into module #525

kevihiiin opened this issue May 24, 2020 · 1 comment

Comments

@kevihiiin
Copy link
Member

The idea is to import all submodules for a module inside the __init__.py file for cleaner access to classes and functions. The module would behave like a big file with all its subclasses.

The proposal @feeds wrote loads all the submodules dynamically on startup. However some (probably all) IDEs fail to detect the dynamically loaded modules resulting in the linter to giving false errors of non-existing modules.


Let's test this with more people of our team whether this works with IDE linting or whether we need special configuration for this to work, which should then maybe be included in the repository.

Originally posted by @bjrne in #509

@kevihiiin
Copy link
Member Author

Some ideas:

  • Create a python stub (similar to header files in c)
  • Apply the "static" hack (manually specifying the imports in an unreachable statement)

The python stub can probably be automatically generated with a pre-commit hook? Not sure if methods can be found if they are missing in the python stub.

Both methods would involve manually adding the files needed to be imported. Leaving it out would only result in the IDE to cry, the code would still work (because of the automatic dynamic import on startup)


Static hack described here:
tensorpack/tensorpack#656
https://github.com/celery/kombu/blob/master/kombu/__init__.py#L24-L35

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant