Restrict any logics inside `__init__.py`
See original GitHub issueSide effect inside __init__.py
are nightmares.
We need to restrict any kind of python
code inside __init__.py
except:
- comments
- docstrings
Imports should be forbidden. Each separate module should have its own public API.
Issue Analytics
- State:
- Created 5 years ago
- Comments:17 (14 by maintainers)
Top Results From Across the Web
python - Module imports and __init__.py - Stack Overflow
So if I should remove all scripts follows if __name__ == '__main__': inside a module to prevent the relative import(s) be broken? –...
Read more >__main__ — Top-level code environment — Python 3.11 ...
This is where using the if __name__ == '__main__' code block comes in handy. Code within this block won't run unless the module...
Read more >Structuring Your Project - The Hitchhiker's Guide to Python
In practical terms, “structure” means making clean code whose logic and dependencies are clear as well as how the files and folders are...
Read more >Python: __init__() is not the only constructor
Some practical use of __new__() can be to restrict the number of objects created from a class, make a singleton and return a...
Read more >how the Python import system works - Ten thousand meters
The reason why we import any module is because we want to get an access to ... The initial idea of requiring __init__.py...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh, great!
What I have in mind is: 0. We need to create new error for this types of issues, let it be
Z400
(as I reserveZ3xx
for classes)ModuleFileVisiter
to check these kinds of featuresOther things that will be required:
noqa
example, since sometimes we really need this feature, and we need a way to disable the check for a single fileThanks for your support!
Yes, you can disable
WPS113
per all__init__.py
files or per line.