-
-
Notifications
You must be signed in to change notification settings - Fork 384
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
Restrict any logics inside __init__.py
#36
Comments
@sobolevn I would like to work on this issue. |
Oh, great! What I have in mind is:
Other things that will be required:
Thanks for your support! |
@sobolevn Sorry, but I have too much other work now. I can still work on this task, but I can't guarantee how soon it will be ready. |
@mcproger ok |
What about importing submodules and populating |
I prefer not to import any kind of stuff in The only possibility to use this hack is when you have a backwards compatibility with clients you don't have in control. This way you go with When you have control over your code and moving things around, just refactor all imports and continue. The same goes for |
If you ever want somebody else to use the tool, you have to adopt current practices, one of them is to populate Maybe we can agree on something in between? For example, to have a check that |
@malinoff can you please elaborate on why |
I suppose you are looking for a technical argument, not philosophical one (like "explicit is better than implicit"). import os
import re
import subprocess
def call_some_command(cmd):
# call the cmd
# parse output with re
# do filesystem manipulation With I guess it's okay-ish if imported modules are easily recognizable for any python developer. But how are you going to distinguish your public apis from, say, specific 3rd party modules? |
Please, keep in mind that And indeed, there's no way to distinguish our API from 3rd party modules, imports, etc. If you really want to make some import protected you can alias it: |
Is there a reason why using all is discouraged? |
@edmondo1984 because it is basically used together with |
If you find that docs do not explain this, please, feel free to send a PR 🙂 |
How do you expose the public api of a package? Think about a package parquet with three files inside:
You want to expose public api
|
from .reader import read_file as read_file
from .writer import write_file as write_file so, this would be compatible with |
This fails with complaints :
Also, if you have a use case like so
this fails, but moving the second import as a relative one like so:
would cause mypy to fail |
Yes, you can disable |
Side effect inside
__init__.py
are nightmares.We need to restrict any kind of
python
code inside__init__.py
except:Imports should be forbidden. Each separate module should have its own public API.
The text was updated successfully, but these errors were encountered: