Skip to content

refactor: add more lint rules #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 1, 2025
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
5 changes: 2 additions & 3 deletions django_object_actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
from .utils import (
BaseDjangoObjectActions,
DjangoObjectActions,
takes_instance_or_queryset,
action,
takes_instance_or_queryset,
)


__all__ = [
"BaseDjangoObjectActions",
"DjangoObjectActions",
"takes_instance_or_queryset",
"action",
"takes_instance_or_queryset",
]
6 changes: 4 additions & 2 deletions django_object_actions/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
Integration tests that actually try and use the tools setup in admin.py
"""

from unittest.mock import patch

from django.contrib.admin.utils import quote
from django.http import HttpResponse
from django.urls import reverse
from unittest.mock import patch

from .tests import LoggedInTestCase
from example_project.polls.factories import (
CommentFactory,
PollFactory,
RelatedDataFactory,
)

from .tests import LoggedInTestCase


class CommentTests(LoggedInTestCase):
def test_action_on_a_model_with_uuid_pk_works(self):
Expand Down
5 changes: 3 additions & 2 deletions django_object_actions/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from unittest import mock

from django.test import TestCase

from example_project.polls.models import Poll

from ..utils import (
BaseDjangoObjectActions,
BaseActionView,
takes_instance_or_queryset,
BaseDjangoObjectActions,
action,
takes_instance_or_queryset,
)


Expand Down
2 changes: 1 addition & 1 deletion django_object_actions/tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.urls import reverse
from django.test import TestCase
from django.urls import reverse

from example_project.polls.factories import UserFactory
from example_project.polls.models import Choice
Expand Down
9 changes: 4 additions & 5 deletions django_object_actions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from django.db.models.query import QuerySet
from django.http import Http404, HttpResponseRedirect
from django.http.response import HttpResponseBase, HttpResponseNotAllowed
from django.urls import re_path, reverse
from django.views.generic import View
from django.views.generic.detail import SingleObjectMixin
from django.views.generic.list import MultipleObjectMixin
from django.urls import re_path, reverse

DEFAULT_METHODS_ALLOWED = ("GET", "POST")
DEFAULT_BUTTON_TYPE = "a"
Expand Down Expand Up @@ -245,8 +245,8 @@ def dispatch(self, request, tool, **kwargs):

try:
view = self.actions[tool]
except KeyError:
raise Http404("Action does not exist")
except KeyError as exc:
raise Http404("Action does not exist") from exc
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL raise from https://peps.python.org/pep-3134/

from 2005!


allowed_methods = getattr(view, "methods", DEFAULT_METHODS_ALLOWED)
if request.method.upper() not in allowed_methods:
Expand Down Expand Up @@ -363,5 +363,4 @@ def decorator(func):

if function is None:
return decorator
else:
return decorator(function)
return decorator(function)
6 changes: 3 additions & 3 deletions example_project/polls/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

from django_object_actions import (
DjangoObjectActions,
takes_instance_or_queryset,
action,
takes_instance_or_queryset,
)

from .models import Choice, Poll, Comment, RelatedData
from .models import Choice, Comment, Poll, RelatedData


class ChoiceAdmin(DjangoObjectActions, admin.ModelAdmin):
Expand Down Expand Up @@ -110,7 +110,7 @@ def delete_all_choices(self, request, obj):

if request.method == "POST":
obj.choice_set.all().delete()
return
return None

self.message_user(request, "All choices deleted")
return render(request, "clear_choices.html", {"object": obj})
Expand Down
3 changes: 1 addition & 2 deletions example_project/polls/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class Meta:

def get_random_string(length):
letters = string.ascii_lowercase
result_str = "".join(random.choice(letters) for i in range(length))
return result_str
return "".join(random.choice(letters) for i in range(length))


class RelatedDataFactory(factory.django.DjangoModelFactory):
Expand Down
2 changes: 1 addition & 1 deletion example_project/polls/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Django 1.9.2 on 2016-02-25 17:25

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
3 changes: 2 additions & 1 deletion example_project/polls/migrations/0002_auto_20200805_0239.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Generated by Django 3.1 on 2020-08-05 02:39

from django.db import migrations, models
import uuid

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
Expand Down
4 changes: 2 additions & 2 deletions example_project/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.urls import path
from django.contrib import admin
from example_project.polls.admin import support_admin
from django.urls import path

from example_project.polls.admin import support_admin

urlpatterns = [
path("admin/", admin.site.urls),
Expand Down
12 changes: 11 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,14 @@ exclude_lines = [
[tool.ruff]

[tool.ruff.lint]
extend-select = ["UP"]
extend-select = [
"A", # flake8-builtins
"B", # flake8-bugbear
"G", # flake8-logging-format
"I", # isort
"N", # pep8-naming
"RET", # flakes8-return
"RUF", # Ruff-specific rules
"UP", # pyupgrade
]
ignore = ["RUF012"]