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

Implicit namespace package is not linted if it is inside a regular package #3944

Open
cl0ne opened this issue Nov 15, 2020 · 6 comments
Open
Labels
False Negative 🦋 No message is emitted but something is wrong with the code Import system namespace-package Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning

Comments

@cl0ne
Copy link

cl0ne commented Nov 15, 2020

Steps to reproduce

  1. Create implicit namespace package inside regular package, for example:
    $ tree package_with_namespace
    package_with_namespace
    ├── __init__.py
    └── namespace
        └── module.py
    
    1 directory, 2 files
  2. Create similar hierarchy when a top-level namespace package contains a regular package with its own namespace package inside, for example:
    $ tree namespace
    namespace
    ├── outer_module.py
    └── package
        ├── __init__.py
        ├── innerspace
        │   ├── inner_module.py
        │   └── inner_package
        │       └── __init__.py
        └── package_module.py
    
    3 directories, 5 files
  3. Put show_warning = True (or something similar) into .py files just to get some warnings.
  4. Run pylint on package_with_namespace, package_with_namespace.namespace and package_with_namespace.namespace.module
  5. Run pylint on namespace

Current behavior

$ pylint package_with_namespace
************* Module package_with_namespace
package_with_namespace/__init__.py:1:0: C0114: Missing module docstring (missing-module-docstring)
package_with_namespace/__init__.py:1:0: C0103: Constant name "show_warning" doesn't conform to UPPER_CASE naming style (invalid-name)

-------------------------------------
Your code has been rated at -10.00/10

$ pylint package_with_namespace.namespace
$ pylint package_with_namespace.namespace.module
************* Module package_with_namespace.namespace.module
package_with_namespace/namespace/module.py:1:0: C0114: Missing module docstring (missing-module-docstring)
package_with_namespace/namespace/module.py:1:0: C0103: Constant name "show_warning" doesn't conform to UPPER_CASE naming style (invalid-name)

-------------------------------------
Your code has been rated at -10.00/10
$ pylint namespace
************* Module namespace.outer_module
namespace/outer_module.py:1:0: C0114: Missing module docstring (missing-module-docstring)
namespace/outer_module.py:1:0: C0103: Constant name "show_warning" doesn't conform to UPPER_CASE naming style (invalid-name)
************* Module namespace.package.package_module
namespace/package/package_module.py:1:0: C0114: Missing module docstring (missing-module-docstring)
namespace/package/package_module.py:1:0: C0103: Constant name "show_warning" doesn't conform to UPPER_CASE naming style (invalid-name)
************* Module namespace.package
namespace/package/__init__.py:1:0: C0114: Missing module docstring (missing-module-docstring)
namespace/package/__init__.py:1:0: C0103: Constant name "show_warning" doesn't conform to UPPER_CASE naming style (invalid-name)
************* Module namespace.package.innerspace.inner_module
namespace/package/innerspace/inner_module.py:1:0: C0114: Missing module docstring (missing-module-docstring)
namespace/package/innerspace/inner_module.py:1:0: C0103: Constant name "show_warning" doesn't conform to UPPER_CASE naming style (invalid-name)
************* Module namespace.package.innerspace.inner_package
namespace/package/innerspace/inner_package/__init__.py:1:0: C0114: Missing module docstring (missing-module-docstring)
namespace/package/innerspace/inner_package/__init__.py:1:0: C0103: Constant name "show_warning" doesn't conform to UPPER_CASE naming style (invalid-name)

-------------------------------------
Your code has been rated at -10.00/10

Expected behavior

Output from pylint package_with_namespace and pylint package_with_namespace.namespace should contain output from pylint package_with_namespace.namespace.module just like with pylint namespace.

pylint --version output

pylint 2.6.0
astroid 2.4.2
Python 3.8.6 (default, Sep 30 2020, 04:00:38) 
[GCC 10.2.0]
@dbaty
Copy link
Contributor

dbaty commented Nov 17, 2020

package_with_namespace/namespace/__init__.py is missing. If I add it, errors in package_with_namespace/namespace/module.py are correctly detected by Pylint.

Python may be able to cope with the absence of __init__.py [1], but pylint does not. I think it's a feature and I would suggest adding missing __init__.py everywhere they are needed.

[1] The Python tutorial says the file is required, though:

The init.py files are required to make Python treat directories containing the file as packages.

@cl0ne
Copy link
Author

cl0ne commented Nov 17, 2020

package_with_namespace/namespace/__init__.py is missing.

I would suggest adding missing __init__.py everywhere they are needed.

Nope, that is intended and conforms to namespace package definition. I named that sub-package namespace to emphasize that it is a namespace package, not a regular one.

[1] The Python tutorial says the file is required, though:

The init.py files are required to make Python treat directories containing the file as packages.

PEP420 has clarifications on this matter, though:

Regular packages will continue to have an __init__.py and will reside in a single directory.
Namespace packages cannot contain an __init__.py.

@dbaty
Copy link
Contributor

dbaty commented Nov 19, 2020

Thanks for the links, I did not know about namespace packages. I'll go back studying the subject and let others chime in. :)

@hippo91 hippo91 added Bug 🪲 False Negative 🦋 No message is emitted but something is wrong with the code Import system labels Nov 26, 2020
@bdegreve
Copy link

bdegreve commented Mar 30, 2021

Nope, that is intended and conforms to namespace package definition. I named that sub-package namespace to emphasize that it is a namespace package, not a regular on

I'm not finding anything in PEP420 that forbids this, but isn't it kind of moot for namespace.package.innerspace to be a namespace? After all, namespace.package can only exist in one space in the filesystem, and thus also namespace.package.innerspace? I.e. you can't split namespace.package.innerspace in two different installations.

I'm asking this, because I was just wondering about this myself ...

@cl0ne
Copy link
Author

cl0ne commented Mar 31, 2021

I'd admit that the second example is made-up, kind of "what if" experiment. And in real world situations it probably doesn't have a lot of sense.

@DanielNoord
Copy link
Collaborator

As a note to self, this will not be fixed with #6405 and requires further investigation.

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.15.0 milestone Jul 14, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning and removed Bug 🪲 labels Jul 14, 2022
@DanielNoord DanielNoord removed this from the 2.15.0 milestone Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Negative 🦋 No message is emitted but something is wrong with the code Import system namespace-package Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning
Projects
None yet
Development

No branches or pull requests

6 participants