Skip to content

Commit

Permalink
Fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Smurf2-pluto committed Nov 29, 2023
1 parent 61c784c commit 7873a4d
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 68 deletions.
4 changes: 3 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ ignore = F401,
E501,
E722,
W605,
E203
E203,
W503,
exclude =
.git,
__pycache__,
.env,
*.pyc,
*.pyo,
*migrations*,
.venv,

per-file-ignores =
__init__.py:F401,
Expand Down
8 changes: 4 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
# 'preamble': '',
}

# Grouping the document tree into LaTeX files. List of tuples
Expand Down Expand Up @@ -271,7 +271,7 @@

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
#'http://docs.python.org/': None,
# 'http://docs.python.org/': None,
"https://docs.djangoproject.com/en/stable": "https://docs.djangoproject.com/en/stable/_objects"
}

Expand Down
2 changes: 1 addition & 1 deletion example/example/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib import admin
from django.urls import include, path, reverse_lazy
from django.urls import path, reverse_lazy
from django.views.generic import RedirectView

admin.autodiscover()
Expand Down
12 changes: 11 additions & 1 deletion example/pexp/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
from django.contrib import admin
from pexp.models import *
from pexp.models import (
Project,
ArtProject,
ResearchProject,
UUIDModelA,
UUIDModelB,
UUIDModelC,
ProxyA,
ProxyB,
ProxyBase,
)

from polymorphic.admin import (
PolymorphicChildModelAdmin,
Expand Down
29 changes: 18 additions & 11 deletions example/pexp/management/commands/p2cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@

from django.core.management import BaseCommand
from django.db import connection
from pexp.models import *
from pexp.models import (
TestModelA,
TestModelB,
TestModelC,
NormalModelA,
NormalModelB,
NormalModelC,
)

rnd = Random()

Expand All @@ -28,7 +35,7 @@ def wrapper(*arg):
connection.queries_log.clear()
for i in range(iterations):
t1 = time.time()
x = func(*arg)
_ = func(*arg)
t2 = time.time()
results.append((t2 - t1) * 1000.0)
res_sum = 0
Expand All @@ -49,19 +56,19 @@ class Command(BaseCommand):
def handle_noargs(self, **options):
if False:
TestModelA.objects.all().delete()
a = TestModelA.objects.create(field1="A1")
b = TestModelB.objects.create(field1="B1", field2="B2")
c = TestModelC.objects.create(field1="C1", field2="C2", field3="C3")
_ = TestModelA.objects.create(field1="A1")
_ = TestModelB.objects.create(field1="B1", field2="B2")
_ = TestModelC.objects.create(field1="C1", field2="C2", field3="C3")
connection.queries_log.clear()
print(TestModelC.base_objects.all())
show_queries()

if False:
TestModelA.objects.all().delete()
for i in range(1000):
a = TestModelA.objects.create(field1=str(i % 100))
b = TestModelB.objects.create(field1=str(i % 100), field2=str(i % 200))
c = TestModelC.objects.create(
_ = TestModelA.objects.create(field1=str(i % 100))
_ = TestModelB.objects.create(field1=str(i % 100), field2=str(i % 200))
_ = TestModelC.objects.create(
field1=str(i % 100), field2=str(i % 200), field3=str(i % 300)
)
if i % 100 == 0:
Expand All @@ -76,9 +83,9 @@ def handle_noargs(self, **options):
return

NormalModelA.objects.all().delete()
a = NormalModelA.objects.create(field1="A1")
b = NormalModelB.objects.create(field1="B1", field2="B2")
c = NormalModelC.objects.create(field1="C1", field2="C2", field3="C3")
_ = NormalModelA.objects.create(field1="A1")
_ = NormalModelB.objects.create(field1="B1", field2="B2")
_ = NormalModelC.objects.create(field1="C1", field2="C2", field3="C3")
qs = TestModelA.objects.raw("SELECT * from pexp_testmodela")
for o in list(qs):
print(o)
Expand Down
14 changes: 7 additions & 7 deletions example/pexp/management/commands/pcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from django.core.management.base import NoArgsCommand
from django.db import connection
from pexp.models import *
from pexp.models import TestModelA, TestModelB, TestModelC, Project, ArtProject, ResearchProject


def reset_queries():
Expand All @@ -16,15 +16,15 @@ class Command(NoArgsCommand):

def handle_noargs(self, **options):
Project.objects.all().delete()
a = Project.objects.create(topic="John's gathering")
b = ArtProject.objects.create(topic="Sculpting with Tim", artist="T. Turner")
c = ResearchProject.objects.create(topic="Swallow Aerodynamics", supervisor="Dr. Winter")
_ = Project.objects.create(topic="John's gathering")
_ = ArtProject.objects.create(topic="Sculpting with Tim", artist="T. Turner")
_ = ResearchProject.objects.create(topic="Swallow Aerodynamics", supervisor="Dr. Winter")
print(Project.objects.all())
print("")

TestModelA.objects.all().delete()
a = TestModelA.objects.create(field1="A1")
b = TestModelB.objects.create(field1="B1", field2="B2")
c = TestModelC.objects.create(field1="C1", field2="C2", field3="C3")
_ = TestModelA.objects.create(field1="A1")
_ = TestModelB.objects.create(field1="B1", field2="B2")
_ = TestModelC.objects.create(field1="C1", field2="C2", field3="C3")
print(TestModelA.objects.all())
print("")
16 changes: 8 additions & 8 deletions example/pexp/management/commands/polybench.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from django.core.management import BaseCommand
from django.db import connection
from pexp.models import *
from pexp.models import TestModelC, NormalModelC

num_objects = 1000

Expand All @@ -31,7 +31,7 @@ def wrapper(*arg):
connection.queries_log.clear()
for i in range(iterations):
t1 = time.time()
x = func(*arg)
_ = func(*arg)
t2 = time.time()
results.append((t2 - t1) * 1000.0)
res_sum = 0
Expand Down Expand Up @@ -79,17 +79,17 @@ def bench_load1_short(model):

def bench_load2(model):
for o in model.objects.all():
f1 = o.field1
f2 = o.field2
f3 = o.field3
_ = o.field1
_ = o.field2
_ = o.field3


def bench_load2_short(model):
for i in range(num_objects / 100):
for o in model.objects.all()[:100]:
f1 = o.field1
f2 = o.field2
f3 = o.field3
_ = o.field1
_ = o.field2
_ = o.field3


def bench_delete(model):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"""

from django.core.management import BaseCommand
from pexp.models import *
from pexp.models import Project, ArtProject, ResearchProject


class Command(BaseCommand):
help = ""

def handle_noargs(self, **options):
Project.objects.all().delete()
o = Project.objects.create(topic="John's gathering")
o = ArtProject.objects.create(topic="Sculpting with Tim", artist="T. Turner")
o = ResearchProject.objects.create(topic="Swallow Aerodynamics", supervisor="Dr. Winter")
_ = Project.objects.create(topic="John's gathering")
_ = ArtProject.objects.create(topic="Sculpting with Tim", artist="T. Turner")
_ = ResearchProject.objects.create(topic="Swallow Aerodynamics", supervisor="Dr. Winter")
print(Project.objects.all())
2 changes: 1 addition & 1 deletion polymorphic/admin/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def queryset(self, request, queryset):
value = None
if value:
# ensure the content type is allowed
for choice_value, _ in self.lookup_choices:
for choice_value, choice_label in self.lookup_choices:
if choice_value == value:
return queryset.filter(polymorphic_ctype_id=choice_value)
raise PermissionDenied(
Expand Down
4 changes: 1 addition & 3 deletions polymorphic/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
import warnings

import django
from django.core.exceptions import ImproperlyConfigured
from django.db import models
from django.db.models.base import ModelBase
from django.db.models.manager import ManagerDescriptor

from .managers import PolymorphicManager
from .query import PolymorphicQuerySet
Expand Down Expand Up @@ -86,7 +84,7 @@ def __new__(self, model_name, bases, attrs, **kwargs):
# determine the name of the primary key field and store it into the class variable
# polymorphic_primary_key_name (it is needed by query.py)
for f in new_class._meta.fields:
if f.primary_key and type(f) != models.OneToOneField:
if f.primary_key and not isinstance(f, models.OneToOneField):
new_class.polymorphic_primary_key_name = f.name
break

Expand Down
7 changes: 3 additions & 4 deletions polymorphic/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def _polymorphic_iterator(self, base_iter):
# Make sure the base iterator is read in chunks instead of
# reading it completely, in case our caller read only a few objects.
for i in range(Polymorphic_QuerySet_objects_per_request):

try:
o = next(base_iter)
base_result_objects.append(o)
Expand Down Expand Up @@ -258,7 +257,8 @@ def _polymorphic_add_immediate_loading(self, field_names):

def _process_aggregate_args(self, args, kwargs):
"""for aggregate and annotate kwargs: allow ModelX___field syntax for kwargs, forbid it for args.
Modifies kwargs if needed (these are Aggregate objects, we translate the lookup member variable)"""
Modifies kwargs if needed (these are Aggregate objects, we translate the lookup member variable)
"""
___lookup_assert_msg = "PolymorphicModel: annotate()/aggregate(): ___ model lookup supported for keyword arguments only"

def patch_lookup(a):
Expand All @@ -285,7 +285,7 @@ def tree_node_test___lookup(my_model, node):
for i in range(len(node.children)):
child = node.children[i]

if type(child) == tuple:
if isinstance(child, tuple):
# this Q object child is a tuple => a kwarg like Q( instance_of=ModelB )
assert "___" not in child[0], ___lookup_assert_msg
else:
Expand Down Expand Up @@ -386,7 +386,6 @@ class self.model, but as a class derived from self.model. We want to re-fetch
).pk

for i, base_object in enumerate(base_result_objects):

if base_object.polymorphic_ctype_id == self_model_class_id:
# Real class is exactly the same as base class, go straight to results
resultlist.append(base_object)
Expand Down
2 changes: 0 additions & 2 deletions polymorphic/query_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# They form a kind of small framework for easily adding more
# functionality to filters and Q objects.
# Probably a more general queryset enhancement class could be made out of them.
from polymorphic import compat

###################################################################################
# PolymorphicQuerySet support functions
Expand All @@ -40,7 +39,6 @@ def translate_polymorphic_filter_definitions_in_kwargs(
"""
additional_args = []
for field_path, val in kwargs.copy().items(): # Python 3 needs copy

new_expr = _translate_polymorphic_filter_definition(
queryset_model, field_path, val, using=using
)
Expand Down
2 changes: 1 addition & 1 deletion polymorphic/showfields.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _showfields_add_regular_fields(self, parts):
out = field.name

# if this is the standard primary key named "id", print it as we did with older versions of django_polymorphic
if field.primary_key and field.name == "id" and type(field) == models.AutoField:
if field.primary_key and field.name == "id" and isinstance(field, models.AutoField):
out += " " + str(getattr(self, field.name))

# otherwise, display it just like all other fields (with correct type, shortened content etc.)
Expand Down
2 changes: 1 addition & 1 deletion polymorphic/tests/admintestcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.contrib.messages.middleware import MessageMiddleware
from django.http.response import HttpResponse
from django.test import RequestFactory, TestCase
from django.urls import clear_url_caches, include, path, reverse, set_urlconf
from django.urls import clear_url_caches, path, reverse, set_urlconf


class AdminTestCase(TestCase):
Expand Down
Loading

0 comments on commit 7873a4d

Please sign in to comment.