-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Discovery strategy is still mysterious w/PEP 420 namespace packages #6989
Comments
I think @gvanrossum is the best person to ask about this. |
This is totally mypy's fault. Namespace packages are only discovered during import following, not during initial file discovery from the command line. I recommend dropping an empty |
Thanks for the follow up Guido. Adding an empty placeholder file isn't really an option for us, for reasons not worth going into here.
Would it make sense, when the
Then you'd just iterate over the elements? Alternatively, if a I'm sure both of these have subtitles that make it tricky. If we must, we'll have to auto-discover the subdirectories ourselves and pass them along on the command line. |
Btw, it looks like this is related to #6385 |
I would rather not have mypy "do the import" -- that could run code which might have undesirable side effects, or it could just fail mysteriously. (In general we're pretty adamant that mypy shouldn't ever run your code in order to check it.) Also mypy won't know that the argument refers to a namespace package until it's too late. I think the approach you mentioned that "does work", I suppose the most surprising part is that Would you be interested in giving this a try? |
Yes! I think it would be fine if the second invocation form was a little inconsistent. Here's how I'm thinking about it. Let's say I do this:
That makes sense to me; I want to check the
Is that a reasonable thing to do? |
I think we all agree that that should work. I was hoping that you'd try to come up with a PR for mypy to make it work that way, since the whole mypy team is basically super distracted by other priorities at the moment... |
Fair enough! I'll give it a go, although it likely won't be until after the week of July 4th. |
See the above PR. I've done internal testing and it works well for us. |
I'm having trouble understanding some of the subtleties of how mypy 0.701 (w/Python 3.7) discovers files to check. Here is a sample directory tree:
linkedin
is a PEP 420 namespace package andlinkedin/foo/__init__.py
is empty.bar.py
contains:When I cd into the
lipy-foo
directory containing thesetup.cfg
, and try to run mypy, it can't find any.py
files to check:Clearly mypy doesn't recurse into the
src
directory to find thelinkedin
namespace package. Other options that don't work include:What does work:
Also, if I add an empty
src/linkedin/__init__.py
file, discovery does work as expected:So PEP 420 style namespace packages do seem to influence the behavior here.
Since we may have additional directories and namespace packages under
src
in other repositories, I'd prefer not to have to invoke mypy withsrc/linkedin
, but there doesn't seem to be any other option.Maybe I'm doing something wrong, so please tell me if this is pebkac, or is unsupported. Should mypy be able to discover the
linkedin
namespace package usingsrc
-style package layouts with PEP 420 namespaces?The text was updated successfully, but these errors were encountered: