Skip to content

Commit

Permalink
Fix git conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Feb 8, 2024
1 parent 402af81 commit 4a833ec
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 55 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Learn more about this config here: https://pre-commit.com/
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-yaml
- id: detect-private-key
Expand All @@ -14,19 +14,19 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 22.10.0
rev: 24.1.1
hooks:
- id: black # See pyproject.toml for args

- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
rev: v2.2.6
hooks:
- id: codespell
additional_dependencies:
- tomli

- repo: https://github.com/asottile/pyupgrade
rev: v3.2.3
rev: v3.15.0
hooks:
- id: pyupgrade
args:
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
custom styles (that use the nodes directly). This also drops the
asttokens dependency as it is no longer required.
* Understand the existence of namespaced packages, thereby allowing
different namespaced pacakages to be defined as local or third party.
different namespaced packages to be defined as local or third party.

0.15 2017-11-06
---------------
Expand Down
14 changes: 7 additions & 7 deletions flake8_import_order/flake8_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from flake8_import_order import __version__
from flake8_import_order.checker import (
DEFAULT_IMPORT_ORDER_STYLE, ImportOrderChecker,
DEFAULT_IMPORT_ORDER_STYLE,
ImportOrderChecker,
)
from flake8_import_order.styles import list_entry_points, lookup_entry_point

Expand Down Expand Up @@ -48,8 +49,7 @@ def add_options(cls, parser):
action="store",
type=str,
help=(
"Style to follow. Available: "
", ".join(cls.list_available_styles())
"Style to follow. Available: " ", ".join(cls.list_available_styles())
),
parse_from_config=True,
)
Expand Down Expand Up @@ -99,9 +99,9 @@ def register_opt(parser, *args, **kwargs):
parser.add_option(*args, **kwargs)
except (optparse.OptionError, TypeError):
# Flake8 2.x registration
parse_from_config = kwargs.pop('parse_from_config', False)
kwargs.pop('comma_separated_list', False)
kwargs.pop('normalize_paths', False)
parse_from_config = kwargs.pop("parse_from_config", False)
kwargs.pop("comma_separated_list", False)
kwargs.pop("normalize_paths", False)
parser.add_option(*args, **kwargs)
if parse_from_config:
parser.config_options.append(args[-1].lstrip('-'))
parser.config_options.append(args[-1].lstrip("-"))
96 changes: 53 additions & 43 deletions flake8_import_order/styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

from flake8_import_order import ClassifiedImport, ImportType, NewLine

Error = namedtuple('Error', ['lineno', 'code', 'message'])
Error = namedtuple("Error", ["lineno", "code", "message"])


def list_entry_points():
return iter_entry_points('flake8_import_order.styles')
return iter_entry_points("flake8_import_order.styles")


def lookup_entry_point(name):
try:
return next(iter_entry_points('flake8_import_order.styles', name=name))
return next(iter_entry_points("flake8_import_order.styles", name=name))
except StopIteration:
raise LookupError(f'Unknown style {name}')
raise LookupError(f"Unknown style {name}")


class Style:
Expand Down Expand Up @@ -46,17 +46,17 @@ def _check_I666(self, current_import): # noqa: N802
if current_import.type == ImportType.MIXED:
yield Error(
current_import.lineno,
'I666',
'Import statement mixes groups',
"I666",
"Import statement mixes groups",
)

def _check_I101(self, current_import): # noqa: N802
correct_names = self.sorted_names(current_import.names)
if correct_names != current_import.names:
corrected = ', '.join(correct_names)
corrected = ", ".join(correct_names)
yield Error(
current_import.lineno,
'I101',
"I101",
"Imported names are in the wrong order. "
"Should be {}".format(corrected),
)
Expand All @@ -73,22 +73,24 @@ def _check_I100(self, previous_import, current_import): # noqa: N802
self._explain_import(previous_import),
)
same_section = self.same_section(
previous_import, current_import,
previous_import,
current_import,
)
if not same_section:
message = f"{message} and in a different group."
yield Error(current_import.lineno, 'I100', message)
yield Error(current_import.lineno, "I100", message)

def _check_I201(self, previous_import, previous, current_import): # noqa: N802,E501
same_section = self.same_section(previous_import, current_import)
has_newline = isinstance(previous, NewLine)
if not same_section and not has_newline:
yield Error(
current_import.lineno,
'I201',
"I201",
"Missing newline between import groups. {}".format(
self._explain_grouping(
current_import, previous_import,
current_import,
previous_import,
)
),
)
Expand All @@ -99,10 +101,11 @@ def _check_I202(self, previous_import, previous, current_import): # noqa: N802,
if same_section and has_newline:
yield Error(
current_import.lineno,
'I202',
"I202",
"Additional newline in a group of imports. {}".format(
self._explain_grouping(
current_import, previous_import,
current_import,
previous_import,
)
),
)
Expand All @@ -118,34 +121,30 @@ def import_key(import_):
@staticmethod
def same_section(previous, current):
same_type = current.type == previous.type
both_first = (
{previous.type, current.type} <= {
ImportType.APPLICATION, ImportType.APPLICATION_RELATIVE,
}
)
both_first = {previous.type, current.type} <= {
ImportType.APPLICATION,
ImportType.APPLICATION_RELATIVE,
}
return same_type or both_first

@staticmethod
def _explain_import(import_):
if import_.is_from:
return "from {}{} import {}".format(
import_.level * '.',
', '.join(import_.modules),
', '.join(import_.names),
import_.level * ".",
", ".join(import_.modules),
", ".join(import_.names),
)
else:
return "import {}".format(', '.join(import_.modules))
return "import {}".format(", ".join(import_.modules))

@staticmethod
def _explain_grouping(current_import, previous_import):
return (
"'{}' is identified as {} and "
"'{}' is identified as {}."
).format(
return ("'{}' is identified as {} and " "'{}' is identified as {}.").format(
Style._explain_import(current_import),
current_import.type.name.title().replace('_', ' '),
current_import.type.name.title().replace("_", " "),
Style._explain_import(previous_import),
previous_import.type.name.title().replace('_', ' '),
previous_import.type.name.title().replace("_", " "),
)


Expand Down Expand Up @@ -201,10 +200,11 @@ def _check_I202(self, previous_import, previous, current_import): # noqa: N802,
if same_section and has_newline and not optional_split:
yield Error(
current_import.lineno,
'I202',
"I202",
"Additional newline in a group of imports. {}".format(
self._explain_grouping(
current_import, previous_import,
current_import,
previous_import,
)
),
)
Expand All @@ -222,7 +222,11 @@ def sorted_names(names):
@staticmethod
def import_key(import_):
return (
import_.type, import_.is_from, import_.level, import_.modules, import_.names
import_.type,
import_.is_from,
import_.level,
import_.modules,
import_.names,
)


Expand All @@ -248,26 +252,32 @@ def sorted_names(names):
def import_key(import_):
if import_.type in {ImportType.THIRD_PARTY, ImportType.APPLICATION}:
return (
import_.type, import_.package, import_.is_from,
import_.level, import_.modules, import_.names,
import_.type,
import_.package,
import_.is_from,
import_.level,
import_.modules,
import_.names,
)
else:
return (
import_.type, '', import_.is_from, import_.level,
import_.modules, import_.names,
import_.type,
"",
import_.is_from,
import_.level,
import_.modules,
import_.names,
)

@staticmethod
def same_section(previous, current):
app_or_third = current.type in {
ImportType.THIRD_PARTY, ImportType.APPLICATION,
ImportType.THIRD_PARTY,
ImportType.APPLICATION,
}
same_type = current.type == previous.type
both_relative = (
previous.type == current.type == ImportType.APPLICATION_RELATIVE
)
both_relative = previous.type == current.type == ImportType.APPLICATION_RELATIVE
same_package = previous.package == current.package
return (
(not app_or_third and same_type or both_relative)
or (app_or_third and same_package)
return (not app_or_third and same_type or both_relative) or (
app_or_third and same_package
)

0 comments on commit 4a833ec

Please sign in to comment.