You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am reporting a bug where mypy doesn't seem to be able to understand native namespace packages.
The current behavior is mypy seems to confuse import paths:
namespace.package.spam.ham.Key
package.spam.ham.Key
#8944 is a related issue, but in this case, mypy reports an arg-type error, saying incompatible type (not Source file found twice). Please see my repro below for more details.
The expected behavior I would like is for mypy not to raise an error.
mypy is invoked from . in the above folder structure, via simply entering mypy (thanks to files)
[mypy]
# Specifies the Python version used to parse and check the target program.
python_version = 3.8
# Shows error codes in error messages.
show_error_codes = True
# Comma-separated list of paths which should be checked by mypy if none are
# given on the command line.
files = namespace
# Enables PEP 420 style namespace packages.
namespace_packages = True
namespace/package/spam/ham.py:10: error: Argument 1 to "add_key" of "DoorWithKeyhole" has incompatible type "package.spam.ham.Key"; expected "namespace.package.spam.ham.Key" [arg-type]
My temporary workaround is a type: ignore[arg-type] comment.
Seems to be because you pass a directory for the ‘files’ argument. Mypy looks inside the directory for files and it doesn’t treat it as a namespace package at that point — the PEP 420 support only works for imports.
I am reporting a bug where mypy doesn't seem to be able to understand native namespace packages.
The current behavior is mypy seems to confuse import paths:
namespace.package.spam.ham.Key
package.spam.ham.Key
#8944 is a related issue, but in this case, mypy reports an
arg-type
error, sayingincompatible type
(notSource file found twice
). Please see my repro below for more details.The expected behavior I would like is for mypy not to raise an error.
Repro
The package follows the native namespace package folder structure from this Python packaging guide.
Folder structure as output by tree:
setup.cfg
mypy is invoked from
.
in the above folder structure, via simply enteringmypy
(thanks tofiles
)door.py
keys.py
mypy output:
My temporary workaround is a
type: ignore[arg-type]
comment.Versions
(also current master of 0.790+dev.2b704df25ca299e6936927be8d41d2ab945cee2a)
The text was updated successfully, but these errors were encountered: