Skip to content
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

Module '<namespace package>' has no attribute '<module/pkg in namespace>' #9619

Closed
jaraco opened this issue Oct 20, 2020 · 4 comments
Closed
Labels
bug mypy got something wrong

Comments

@jaraco
Copy link
Member

jaraco commented Oct 20, 2020

Bug Report

Attempting to run mypy on jaraco.ui, I'm getting an error:

_________________________________________________ jaraco/ui/cmdline.py _________________________________________________
5: error: Module 'jaraco' has no attribute 'text'

Here is the pertinent code, namely:

from jaraco import text

The module text is supplied by a separate package jaraco.text. The jaraco namespace uses the pkgutil style namespaces (mostly for historical reasons as the code is Python 3-only now, but could still interact with older builds).

This issue is related to #9393, although that issue indicates a different failure mode. Also possibly relevant #6385, #7029.

To Reproduce

git clone https://github.com/jaraco/jaraco.ui
cd jaraco.ui
git checkout eacca37
tox -- -k cmdline

Expected Behavior

mypy should recognize working implementations of extant modules and not fail.

Actual Behavior

Error reported above is emitted.

Your Environment

  • Mypy version used: 0.790
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files):
    ignore_missing_imports = True
  • Python version used: 3.9.0
  • Operating system and version: macOS 10.15
@jaraco jaraco added the bug mypy got something wrong label Oct 20, 2020
@jaraco
Copy link
Member Author

jaraco commented Oct 20, 2020

Interestingly, even though I've started running mypy on all of the projects I maintain, including many importing the jaraco.* namespace, only this one line has given me grief, so the issue may be isolated to the from <namespace> import <module> syntax.

@vbarbaresi
Copy link
Contributor

vbarbaresi commented Oct 25, 2020

The tox command didn't work for me, I ran pip install . mypy and
python -m mypy . --ignore-missing-imports
Then I was able to reproduce the issue with mypy v0.790

I tried using mypy from the latest master branch: there's a different error pointing to the source of the problem:

python -m mypy . --ignore-missing-imports
venv/lib/python3.8/site-packages/jaraco/__init__.py: error: Duplicate module named 'jaraco' (also at './jaraco/__init__.py')
venv/lib/python3.8/site-packages/jaraco/__init__.py: error: Are you missing an __init__.py?

I traced it back to #9614 (which is related to the issue #6385 you mentioned)

It doesn't really solve the original issue though, it reappears when running:
mypy jaraco/ui/cmdline.py or mypy -p jaraco
Adding --namespace-packages doesn't change anything
I don't know how to fix that, it seems tricky

@hauntsaninja
Copy link
Collaborator

This is a duplicate of #9393

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Aug 3, 2022
@jaraco
Copy link
Member Author

jaraco commented Aug 3, 2022

Since my original post, the jaraco namespace has migrated away from pkgutil-style namespaces (to native PEP 420 namespaces).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants