pylint/checkers/imports.py
def _check_imports_order(self, _module_node):
        """Checks imports of module `node` are grouped by category

        Imports must follow this order: standard, 3rd party, local
        """
        std_imports = []
        third_party_imports = []
        first_party_imports = []
        # need of a list that holds third or first party ordered import
        external_imports = []
        local_imports = []
        third_party_not_ignored = []
        first_party_not_ignored = []
        local_not_ignored = []
        isort_obj = isort.SortImports(
            file_contents="",
            known_third_party=self.config.known_third_party,
            known_standard_library=self.config.known_standard_library,
        )
        for node, modname in self._imports_stack:
            if modname.startswith("."):
                package = "." + modname.split(".")[1]
            else:
                package = modname.split(".")[0]
            nested = not isinstance(node.parent, astroid.Module)
            ignore_for_import_order = not self.linter.is_message_enabled(
                "wrong-import-order", node.fromlineno
            )
            import_category = isort_obj.place_module(package)
            node_and_package_import = (node, package)
            if import_category in ("FUTURE", "STDLIB"):
                std_imports.append(node_and_package_import)
                wrong_import = (
                    third_party_not_ignored
                    or first_party_not_ignored
                    or local_not_ignored
                )
                if self._is_fallback_import(node, wrong_import):
                    continue
                if wrong_import and not nested:
                    self.add_message(
                        "wrong-import-order",
                        node=node,
                        args=(
                            'standard import "%s"' % node.as_string(),
                            '"%s"' % wrong_import[0][0].as_string(),
                        ),
                    )
            elif import_category == "THIRDPARTY":
                third_party_imports.append(node_and_package_import)
                external_imports.append(node_and_package_import)
                if not nested and not ignore_for_import_order:
                    third_party_not_ignored.append(node_and_package_import)
                wrong_import = first_party_not_ignored or local_not_ignored
                if wrong_import and not nested:
                    self.add_message(
                        "wrong-import-order",
                        node=node,
                        args=(
                            'third party import "%s"' % node.as_string(),
                            '"%s"' % wrong_import[0][0].as_string(),
                        ),
                    )
            elif import_category == "FIRSTPARTY":
                first_party_imports.append(node_and_package_import)
                external_imports.append(node_and_package_import)
                if not nested and not ignore_for_import_order:
                    first_party_not_ignored.append(node_and_package_import)
                wrong_import = local_not_ignored
                if wrong_import and not nested:
                    self.add_message(
                        "wrong-import-order",
                        node=node,
                        args=(
                            'first party import "%s"' % node.as_string(),
                            '"%s"' % wrong_import[0][0].as_string(),
                        ),
                    )
            elif import_category == "LOCALFOLDER":
                local_imports.append((node, package))
                if not nested and not ignore_for_import_order:
                    local_not_ignored.append((node, package))
        return std_imports, external_imports, local_imports
def _check_imports_order(self, _module_node):
        std_imports = []
        third_party_imports = []
        first_party_imports = []
        # need of a list that holds third or first party ordered import
        external_imports = []
        local_imports = []
        third_party_not_ignored = []
        first_party_not_ignored = []
        local_not_ignored = []
        isort_obj = isort.SortImports(
            file_contents="",
            known_third_party=self.config.known_third_party,
            known_standard_library=self.config.known_standard_library,
        )
        for node, modname in self._imports_stack:
            if modname.startswith("."):
                package = "." + modname.split(".")[1]
            else:
                package = modname.split(".")[0]
            nested = not isinstance(node.parent, astroid.Module)
            ignore_for_import_order = not self.linter.is_message_enabled(
                "wrong-import-order", node.fromlineno
            )
            import_category = isort_obj.place_module(package)
            node_and_package_import = (node, package)
            if import_category in ("FUTURE", "STDLIB"):
                std_imports.append(node_and_package_import)
                wrong_import = (
                    third_party_not_ignored
                    or first_party_not_ignored
                    or local_not_ignored
                )
                if self._is_fallback_import(node, wrong_import):
                    continue
                if wrong_import and not nested:
                    self.add_message(
                        "wrong-import-order",
                        node=node,
                        args=(
                            'standard import "%s"' % node.as_string(),
                            '"%s"' % wrong_import[0][0].as_string(),
                        ),
                    )
            elif import_category == "THIRDPARTY":
                third_party_imports.append(node_and_package_import)
                external_imports.append(node_and_package_import)
                if not nested and not ignore_for_import_order:
                    third_party_not_ignored.append(node_and_package_import)
                wrong_import = first_party_not_ignored or local_not_ignored
                if wrong_import and not nested:
                    self.add_message(
                        "wrong-import-order",
                        node=node,
                        args=(
                            'third party import "%s"' % node.as_string(),
                            '"%s"' % wrong_import[0][0].as_string(),
                        ),
                    )
            elif import_category == "FIRSTPARTY":
                first_party_imports.append(node_and_package_import)
                external_imports.append(node_and_package_import)
                if not nested and not ignore_for_import_order:
                    first_party_not_ignored.append(node_and_package_import)
                wrong_import = local_not_ignored
                if wrong_import and not nested:
                    self.add_message(
                        "wrong-import-order",
                        node=node,
                        args=(
                            'first party import "%s"' % node.as_string(),
                            '"%s"' % wrong_import[0][0].as_string(),
                        ),
                    )
            elif import_category == "LOCALFOLDER":
                local_imports.append((node, package))
                if not nested and not ignore_for_import_order:
                    local_not_ignored.append((node, package))
        return std_imports, external_imports, local_imports
def _check_imports_order ( self , _module_node ) : std_imports = [ ] third_party_imports = [ ] first_party_imports = [ ] # need of a list that holds third or first party ordered import external_imports = [ ] local_imports = [ ] third_party_not_ignored = [ ] first_party_not_ignored = [ ] local_not_ignored = [ ] isort_obj = isort . SortImports ( file_contents = "" , known_third_party = self . config . known_third_party , known_standard_library = self . config . known_standard_library , ) for node , modname in self . _imports_stack : if modname . startswith ( "." ) : package = "." + modname . split ( "." ) [ 1 ] else : package = modname . split ( "." ) [ 0 ] nested = not isinstance ( node . parent , astroid . Module ) ignore_for_import_order = not self . linter . is_message_enabled ( "wrong-import-order" , node . fromlineno ) import_category = isort_obj . place_module ( package ) node_and_package_import = ( node , package ) if import_category in ( "FUTURE" , "STDLIB" ) : std_imports . append ( node_and_package_import ) wrong_import = ( third_party_not_ignored or first_party_not_ignored or local_not_ignored ) if self . _is_fallback_import ( node , wrong_import ) : continue if wrong_import and not nested : self . add_message ( "wrong-import-order" , node = node , args = ( 'standard import "%s"' % node . as_string ( ) , '"%s"' % wrong_import [ 0 ] [ 0 ] . as_string ( ) , ) , ) elif import_category == "THIRDPARTY" : third_party_imports . append ( node_and_package_import ) external_imports . append ( node_and_package_import ) if not nested and not ignore_for_import_order : third_party_not_ignored . append ( node_and_package_import ) wrong_import = first_party_not_ignored or local_not_ignored if wrong_import and not nested : self . add_message ( "wrong-import-order" , node = node , args = ( 'third party import "%s"' % node . as_string ( ) , '"%s"' % wrong_import [ 0 ] [ 0 ] . as_string ( ) , ) , ) elif import_category == "FIRSTPARTY" : first_party_imports . append ( node_and_package_import ) external_imports . append ( node_and_package_import ) if not nested and not ignore_for_import_order : first_party_not_ignored . append ( node_and_package_import ) wrong_import = local_not_ignored if wrong_import and not nested : self . add_message ( "wrong-import-order" , node = node , args = ( 'first party import "%s"' % node . as_string ( ) , '"%s"' % wrong_import [ 0 ] [ 0 ] . as_string ( ) , ) , ) elif import_category == "LOCALFOLDER" : local_imports . append ( ( node , package ) ) if not nested and not ignore_for_import_order : local_not_ignored . append ( ( node , package ) ) return std_imports , external_imports , local_imports
Checks imports of module `node` are grouped by category

        Imports must follow this order: standard, 3rd party, local
Checks imports of module node are grouped by category