implicit-namespace-package (INP001) | 隐式命名空间包 (INP001)
Derived from the flake8-no-pep420 linter. | 源自 flake8-no-pep420 linter。
作用
Checks for packages that are missing an __init__.py
file. | 检查缺少 __init__.py
文件的包。
为什么这不好?
Python packages are directories that contain a file named __init__.py
. The existence of this file indicates that the directory is a Python package, and so it can be imported the same way a module can be imported. | Python 包是包含名为 __init__.py
文件的目录。 此文件的存在表明该目录是一个 Python 包,因此可以像导入模块一样导入它。
Directories that lack an __init__.py
file can still be imported, but they're indicative of a special kind of package, known as a "namespace package" (see: PEP 420). Namespace packages are less widely used, so a package that lacks an __init__.py
file is typically meant to be a regular package, and the absence of the __init__.py
file is probably an oversight. | 缺少 __init__.py
文件的目录仍然可以被导入,但它们指示了一种特殊的包,称为“命名空间包”(参见:PEP 420)。 命名空间包使用较少,因此缺少 __init__.py
文件的包通常是指一个常规包,而缺少 __init__.py
文件可能是一个疏忽。