Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/user_guide/configuration/all-options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,13 @@ Standard Checkers
**Default:** ``()``


--known-first-party
"""""""""""""""""""
*Force import order to recognize a module as part of a first party library.*

**Default:** ``()``


--known-third-party
"""""""""""""""""""
*Force import order to recognize a module as part of a third party library.*
Expand Down Expand Up @@ -1082,6 +1089,8 @@ Standard Checkers
known-standard-library = []
known-first-party = []
known-third-party = ["enchant"]
preferred-modules = []
Expand Down
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/10803.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add support for `--known-first-party` similar to `--known-third-party`.

Refs #10803
3 changes: 3 additions & 0 deletions examples/pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ int-import-graph=
# compatibility libraries.
known-standard-library=

# Force import order to recognize a module as part of a first party library.
known-first-party=

# Force import order to recognize a module as part of a third party library.
known-third-party=enchant

Expand Down
3 changes: 3 additions & 0 deletions examples/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ max-module-lines = 1000
# libraries.
# known-standard-library =

# Force import order to recognize a module as part of a third party library.
# known-first-party =

# Force import order to recognize a module as part of a third party library.
known-third-party = [ "enchant" ]

Expand Down
12 changes: 12 additions & 0 deletions pylint/checkers/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ def _make_graph(


DEFAULT_STANDARD_LIBRARY = ()
DEFAULT_KNOWN_FIRST_PARTY = ()
DEFAULT_KNOWN_THIRD_PARTY = ("enchant",)
DEFAULT_PREFERRED_MODULES = ()

Expand Down Expand Up @@ -401,6 +402,16 @@ class ImportsChecker(DeprecatedMixin, BaseChecker):
"the standard compatibility libraries.",
},
),
(
"known-first-party",
{
"default": DEFAULT_KNOWN_FIRST_PARTY,
"type": "csv",
"metavar": "<modules>",
"help": "Force import order to recognize a module as part of "
"a first party library.",
},
),
(
"known-third-party",
{
Expand Down Expand Up @@ -758,6 +769,7 @@ def _isort_config(self) -> isort.Config:
# KNOWN_standard_library for ages in pylint, and we
# don't want to break compatibility.
extra_standard_library=self.linter.config.known_standard_library,
known_first_party=self.linter.config.known_first_party,
known_third_party=self.linter.config.known_third_party,
)

Expand Down
6 changes: 5 additions & 1 deletion tests/functional/w/wrong_import_order2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
import os
from sys import argv

# external imports
# external/third-party imports
import isort
import datetime # std import that should be treated as third-party

# First-party imports
from six import moves

import pylint
import re # std import that should be treated as first-party

# local_imports
from . import my_package
from .my_package import myClass
1 change: 1 addition & 0 deletions tests/functional/w/wrong_import_order2.rc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[IMPORTS]
known-first-party=re
known-third-party=datetime