import-private-name / C2701ΒΆ

Message emitted:

Imported private %s (%s)


Used when a private module or object prefixed with _ is imported. PEP8 guidance on Naming Conventions states that public attributes with leading underscores should be considered private.

Problematic code:

from argparse import _AttributeHolder, _SubParsersAction  # [import-private-name]

attr_holder = _AttributeHolder()

def add_sub_parser(sub_parsers: _SubParsersAction):
    # ...

Correct code:

"""Private import can be used as type annotations."""

from argparse import _SubParsersAction

def add_sub_parser(sub_parsers: _SubParsersAction):
    # ...

Configuration file:

load-plugins = pylint.extensions.private_import

Additional details:

Using private imports expose you to unexpected breaking changes for any version bump of your dependencies, even in patch versions.


This message is emitted by the optional 'import-private-name' checker, which requires the pylint.extensions.private_import plugin to be loaded.

Created by the import-private-name checker.