Skip to content

"cannot perform relative import" with namespace packages #9307

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

Closed
lilydjwg opened this issue Aug 14, 2020 · 1 comment
Closed

"cannot perform relative import" with namespace packages #9307

lilydjwg opened this issue Aug 14, 2020 · 1 comment

Comments

@lilydjwg
Copy link

mkdir t
echo 'FOO = 1' > t/a.py
echo 'from . import a' > t/b.py
mypy t
  • What is the actual behavior/output?
t/b.py:1: error: No parent module -- cannot perform relative import
Found 1 error in 1 file (checked 2 source files)
  • What is the behavior/output you expect?
Success: no issues found in 2 source files
  • What are the versions of mypy and Python you are using?

mypy 0.782 and Python 3.8.5

  • Do you see the same issue after installing mypy from Git master?

yes

  • What are the mypy flags you are using? (For example --strict-optional)

None.

@gvanrossum
Copy link
Member

When you pass a directory to mypy, it type-checks the files in the directory, assuming the directory is not a package. To treat the directory as a package, you would need to use mypy -p t. Unfortunately there's still a bug there and the workaround is to add an empty __init__.pyi to the directory.

Closing as duplicate of #5759.

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

No branches or pull requests

2 participants