From 83fa6caa9ece05ab90d85e2ea9c2cb9c438730ed Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Wed, 9 Oct 2024 21:19:09 +0200 Subject: [PATCH 1/4] [ruff] Fix the section of select in the pyproject.toml --- pyproject.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 82b8fc7..5586a57 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,16 +66,16 @@ line-length = 120 [tool.ruff] line-length = 120 -select = [ +lint.select = [ + "B", # bugbear "E", # pycodestyle "F", # pyflakes - "W", # pycodestyle - "B", # bugbear "I", # isort "RUF", # ruff "UP", # pyupgrade + "W", # pycodestyle ] -ignore = [ +lint.ignore = [ "RUF012", # Mutable class attributes should be annotated with `typing.ClassVar` ] From feec3361a79c2d596003b9071a03f8044c8f1e9e Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Wed, 9 Oct 2024 21:21:23 +0200 Subject: [PATCH 2/4] [ruff] Add consider-merging-multiple-comparison It's long so it's formatting the pyproject.toml to avoid conflict --- pyproject.toml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5586a57..f840ad0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,13 +67,14 @@ line-length = 120 [tool.ruff] line-length = 120 lint.select = [ - "B", # bugbear - "E", # pycodestyle - "F", # pyflakes - "I", # isort - "RUF", # ruff - "UP", # pyupgrade - "W", # pycodestyle + "B", # bugbear + "E", # pycodestyle + "F", # pyflakes + "I", # isort + "PLR1714", # Consider merging multiple comparisons + "RUF", # ruff + "UP", # pyupgrade + "W", # pycodestyle ] lint.ignore = [ "RUF012", # Mutable class attributes should be annotated with `typing.ClassVar` From 359f39731ac17ab31aa95d8dc2ce849bdf9c4aa6 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Wed, 9 Oct 2024 21:29:21 +0200 Subject: [PATCH 3/4] [ruff] Add flake8-pie, flake8-pyi, pygrep-hooks, future annotations --- pylint_django/checkers/foreign_key_strings.py | 3 ++- pylint_django/tests/test_func.py | 2 +- pyproject.toml | 5 +++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pylint_django/checkers/foreign_key_strings.py b/pylint_django/checkers/foreign_key_strings.py index bb61b72..20b102e 100644 --- a/pylint_django/checkers/foreign_key_strings.py +++ b/pylint_django/checkers/foreign_key_strings.py @@ -83,7 +83,8 @@ def open(self): import django # pylint: disable=import-outside-toplevel django.setup() - from django.apps import apps # noqa pylint: disable=import-outside-toplevel,unused-import + # pylint: disable-next=import-outside-toplevel,unused-import + from django.apps import apps # noqa: F401 except ImproperlyConfigured: # this means that Django wasn't able to configure itself using some defaults diff --git a/pylint_django/tests/test_func.py b/pylint_django/tests/test_func.py index 2c444e8..51cfc6f 100644 --- a/pylint_django/tests/test_func.py +++ b/pylint_django/tests/test_func.py @@ -54,7 +54,7 @@ def __init__(self, test_file): # if hasattr(test_file, 'option_file') and test_file.option_file is None: # pylint: disable=super-with-arguments # TODO Fix this and the CI (?) - super(PylintDjangoLintModuleTest, self).__init__(test_file) # noqa + super(PylintDjangoLintModuleTest, self).__init__(test_file) # noqa: UP008 self._linter.load_plugin_modules(["pylint_django"]) self._linter.load_plugin_configuration() diff --git a/pyproject.toml b/pyproject.toml index f840ad0..ca879b4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,9 +70,14 @@ lint.select = [ "B", # bugbear "E", # pycodestyle "F", # pyflakes + "FA100", # add future annotations "I", # isort + "PGH004", # pygrep-hooks - Use specific rule codes when using noqa + "PIE", # flake8-pie "PLR1714", # Consider merging multiple comparisons + "PYI", # flake8-pyi "RUF", # ruff + "T100", # flake8-debugger "UP", # pyupgrade "W", # pycodestyle ] From c8295bb2178bf33ae6410edf4c7c5c868f4f14fd Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Wed, 9 Oct 2024 21:35:05 +0200 Subject: [PATCH 4/4] [ruff] Activate ruff's pylint messages --- pylint_django/augmentations/__init__.py | 13 ++++++------- pylint_django/checkers/models.py | 2 +- pyproject.toml | 9 ++++++++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/pylint_django/augmentations/__init__.py b/pylint_django/augmentations/__init__.py index 1ff4c41..a5eef37 100644 --- a/pylint_django/augmentations/__init__.py +++ b/pylint_django/augmentations/__init__.py @@ -366,12 +366,11 @@ class ModelB(models.Model): # if this is a X_set method, that's a pretty strong signal that this is the default # Django name, rather than one set by related_name quack = True - else: - # we will - if isinstance(node.parent, Attribute): - func_name = getattr(node.parent, "attrname", None) - if func_name in MANAGER_ATTRS: - quack = True + # we will + elif isinstance(node.parent, Attribute): + func_name = getattr(node.parent, "attrname", None) + if func_name in MANAGER_ATTRS: + quack = True if quack: children = list(node.get_children()) @@ -522,7 +521,7 @@ def _attribute_is_magic(node, attrs, parents): try: for cls in node.last_child().inferred(): if isinstance(cls, Super): - cls = cls._self_class # pylint: disable=protected-access + cls = cls._self_class # pylint: disable=protected-access # noqa:PLW2901 if node_is_subclass(cls, *parents) or cls.qname() in parents: return True except InferenceError: diff --git a/pylint_django/checkers/models.py b/pylint_django/checkers/models.py index 76a6b9f..7ff130a 100644 --- a/pylint_django/checkers/models.py +++ b/pylint_django/checkers/models.py @@ -79,7 +79,7 @@ class ModelChecker(BaseChecker): msgs = MESSAGES @check_messages("model-missing-unicode") - def visit_classdef(self, node): + def visit_classdef(self, node): # noqa: PLR0911 """Class visitor.""" if not node_is_subclass(node, "django.db.models.base.Model", ".Model"): # we only care about models diff --git a/pyproject.toml b/pyproject.toml index ca879b4..0f25404 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,7 +74,11 @@ lint.select = [ "I", # isort "PGH004", # pygrep-hooks - Use specific rule codes when using noqa "PIE", # flake8-pie + "PLC", # pylint convention + "PLE", # pylint error + "PLR", # pylint refactor "PLR1714", # Consider merging multiple comparisons + "PLW", # pylint warning "PYI", # flake8-pyi "RUF", # ruff "T100", # flake8-debugger @@ -82,7 +86,10 @@ lint.select = [ "W", # pycodestyle ] lint.ignore = [ - "RUF012", # Mutable class attributes should be annotated with `typing.ClassVar` + "PLR0912", # Too many branches, worse than C901 + "PLR0915", # Too many statements, worse than C901 + "PLR2004", # Magic value used in comparison, opinionated + "RUF012", # Mutable class attributes should be annotated with `typing.ClassVar` ] [tool.isort]