Skip to content

Add a checker for superfluous import a statements when there is already import a.b #9873

Open
@e-gebes

Description

@e-gebes

Current problem

I was reading the documentation for ungrouped-imports:

https://pylint.readthedocs.io/en/stable/user_guide/messages/convention/ungrouped-imports.html

Under "Correct code" it says:

import logging
import logging.config

But for me this is not "correct", but bad style because import logging is superfluous anyway. logging is implicitly imported with import logging.config.

See also:

https://docs.python.org/3/reference/simple_stmts.html#the-import-statement ("Examples")
https://docs.python.org/3/reference/import.html#the-module-cache

Desired solution

I suggest to change the example in the documentation to use logging.config and logging.handlers.

I also suggest to introduce a checker to warn about such superfluous import statements.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Enhancement ✨Improvement to a componentHelp wanted 🙏Outside help would be appreciated, good for new contributorsNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions