import-private-name / C2701ΒΆ

Message emitted:

Imported private %s (%s)

Description:

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):
    sub_parsers.add_parser("my_subparser")
    # ...

Correct code:

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

from argparse import _SubParsersAction


def add_sub_parser(sub_parsers: _SubParsersAction):
    sub_parsers.add_parser("my_subparser")
    # ...

Configuration file:

[main]
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.

Note

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.