From 2e97bc1886c32be3e52d044cf39e1feb2618729e Mon Sep 17 00:00:00 2001 From: George Hickman Date: Tue, 21 May 2024 16:05:29 -0400 Subject: [PATCH 1/3] swap flake8 for ruff The conflicting errors and warnings from flake8 are already handled by ruff. --- .flake8 | 12 ------------ .pre-commit-config.yaml | 11 +++-------- pyproject.toml | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 20 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 3d7becca..00000000 --- a/.flake8 +++ /dev/null @@ -1,12 +0,0 @@ -[flake8] -exclude = .direnv, .env, .venv, venv -ignore = - # whitespace before ':' (conflicts with Black) - E203 - # line too long (probably right, but if Black let it go, Flake8 should too) - E501 - # line break before binary operator (conflicts with Black) - W503 - # multiple statements on one line (conflicts with Black) - E704 -max_line_length = 88 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6ecd715e..01a5474c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,15 +13,10 @@ repos: hooks: - id: black - - repo: https://github.com/PyCQA/flake8 - rev: 7.0.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.4.4 hooks: - - id: flake8 - - - repo: https://github.com/timothycrosley/isort - rev: 5.13.2 - hooks: - - id: isort + - id: ruff - repo: https://github.com/asottile/pyupgrade rev: v3.15.2 diff --git a/pyproject.toml b/pyproject.toml index a3a18464..ea805622 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,3 +38,25 @@ DJANGO_SETTINGS_MODULE = "core.settings" python_files = [ "test_*.py", ] + +[tool.ruff] +extend-exclude = [ + ".env", +] +target-version = "py310" + +[tool.ruff.lint] +extend-select = [ + "A", # flake8-builtins + "I", # isort + "INP", # flake8-no-pep420 + "ISC", # flake8-implicit-str-concat + "UP", # pyupgrade + "W", # pycodestyle warning +] +extend-ignore = [ + "E731", # allow lambda assignment +] + +[tool.ruff.lint.isort] +lines-after-imports = 2 From 046bdc4826209e5638bb115e94426068740f5516 Mon Sep 17 00:00:00 2001 From: George Hickman Date: Tue, 21 May 2024 16:06:50 -0400 Subject: [PATCH 2/3] Replace format()s with f-strings to fix UP032 errors --- tests/factories.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/factories.py b/tests/factories.py index 22a701bf..3ac6ffac 100644 --- a/tests/factories.py +++ b/tests/factories.py @@ -15,7 +15,7 @@ class Meta: model = Module project_version = factory.SubFactory(ProjectVersionFactory) - name = factory.Sequence("module{}".format) + name = factory.Sequence(lambda n: f"module{n}") class KlassFactory(factory.django.DjangoModelFactory): @@ -25,11 +25,7 @@ class Meta: module = factory.SubFactory(ModuleFactory) name = factory.Sequence("klass{}".format) line_number = 1 - import_path = factory.LazyAttribute( - lambda a: "Django.{module}".format( - module=a.module.name, - ) - ) + import_path = factory.LazyAttribute(lambda a: f"Django.{a.module.name}") class InheritanceFactory(factory.django.DjangoModelFactory): From 7398948dd3e597c8542bd9fbe3cbf3942523e3c0 Mon Sep 17 00:00:00 2001 From: George Hickman Date: Tue, 21 May 2024 16:07:06 -0400 Subject: [PATCH 3/3] Use the | syntax for issubclass instead of a tuple to stop UP038 errors --- cbv/importer/importers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cbv/importer/importers.py b/cbv/importer/importers.py index 9e77120f..28d69180 100644 --- a/cbv/importer/importers.py +++ b/cbv/importer/importers.py @@ -111,7 +111,7 @@ def _handle_class_on_module( if inspect.getsourcefile(member) != inspect.getsourcefile(parent): return None - if issubclass(member, (Exception, Warning)): + if issubclass(member, Exception | Warning): return None yield Klass(