-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Warn about missing __init__.py #2773
Comments
Not also that in Python 3, a directory without |
I'm not seeing this message come through on release 0.521... I got stung by this, and wanted to prevent anyone else from having to go through this by reminding y'all 😀 |
At Instagram this behavior has been a common cause of new packages silently not being typechecked, and nobody realizing it until much later. Somebody will add a new package without an It would be great to have an option to explicitly specify the package root and not require |
I agree it would be nice to have a way to override this. The "crawl-up" behavior is only needed for files passed on the command line. @carljm -- do you pass files inside BTW what exactly do you mean by "package root"? For a module |
I meant the parent; the directory that would be on
Not as part of any automated flow, but it's likely that a developer may do this locally when debugging some type errors; it would be confusing if it didn't work correctly. For our automated full typecheck we just run
Not sure I fully understand what you're suggesting here, but it seems like it might be possible to leverage Another option that comes to mind is to assume (maybe opt-in based on a config flag) that the directory containing |
What about something like this in the config file:
|
I don't think "root" is a common part of Python's terminology about imports (though it seems to be when talking about distributions). We usually talk about "import path", and it's always thought of as a list of directories; for individual directories we say "path entry". I like to just add a flag (command line and in mypy.ini) that changes the behavior so that it doesn't try to crawl up the filename to find additional path entries, but instead searches the search path (current directory plus MYPYPATH) for the file and complains loudly if a file isn't on those. And perhaps the flag would also make it so that if you pass any directories on the command line if will treat those directories as path entries. |
Presuming "searches the search path" implements Py3-compatible behavior (willingness to import packages without
Not sure that makes sense. E.g. in our case, say the correct import path entry is |
OK, sounds good. Let's name the flag |
Given the conclusion here, it seems this is a dupe of #1645. |
This is a duplicate of #1645. |
I have to say that I find this
https://github.com/TheAlgorithms/Python is a (100k+ GitHub stars) repo of algorithms in Python. Most files are standalone implementations of algorithms with few if any imports. I don't believe that we need packages or namespace packages. I would like to gradually introduce type checking and have determined which directories currently have no mypy issues.
I comment out the Is there a tool that I can run that will create mypy's required I know that type checking will help us find bugs but I am unclear how to implement it in projects. Thanks for all the great work! |
It's at best confusing to post on dead, years old issues. Pretty much everything talked about here is out of date (including your stackoverflow link, as it happens). In case other people stumble upon this, you're best served by reading https://mypy.readthedocs.io/en/latest/running_mypy.html#mapping-file-paths-to-modules In your case, it's clear the issue is with pre-commit. I'm guessing what's happening is pre-commit is using git magic to additionally pass in a bunch of files in the command. This obviously isn't what you want, since you want typing enforced only on a couple folders and it's obviously not what mypy wants, since mypy is complaining about the duplication. It looks like the relevant pre-commit incantation is setting |
Definitely read comment the most recent comment above. |
If a package doesn't have an
__init__.py
file, the error message from mypy isn't very helpful (e.g.,Can't find package 'abc'
), and sometimes users can't figure this out by themselves. If mypy can't find a package, it could see if the directory exists somewhere in the module search path without an__init__.py
, and give a message that says this explicitly.Examples of potential better messages:
The text was updated successfully, but these errors were encountered: