Skip to content

Commit 233a68b

Browse files
committed
Add pycodestyle rules
1 parent bbb9b32 commit 233a68b

File tree

24 files changed

+100
-74
lines changed

24 files changed

+100
-74
lines changed

oioioi/base/menu.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ def _get_all_registered_items(self, request):
9595
def __init__(self, text=None, condition=None, show_icons=False):
9696
self.text = text
9797
if condition is None:
98-
condition = lambda request: True
98+
def condition(request):
99+
return True
99100
self.condition = condition
100101
self.show_icons = show_icons
101102
self._registry = []

oioioi/base/models.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
33

44
import django.dispatch
55
from django.conf import settings
6+
from django.contrib.auth.models import User
7+
from django.db import models
8+
from django.db.models.signals import post_save
9+
from django.dispatch import receiver
10+
from django.utils.translation import gettext_lazy as _
611

712
# pylint: disable=unused-import
813
# Important. This import is to register signal handlers. Do not remove it.
914
import oioioi.base.signal_handlers # noqa: F401
1015
from oioioi.base.captcha_check import captcha_check
1116
from oioioi.base.setup_check import setup_check
1217

18+
import logging
19+
1320
# Check if deployment and installation config versions match.
1421
# Check if database settings are correct.
1522
setup_check()
@@ -24,14 +31,6 @@
2431
except ImportError:
2532
pass
2633

27-
import logging
28-
29-
from django.contrib.auth.models import User
30-
from django.db import models
31-
from django.db.models.signals import post_save
32-
from django.dispatch import receiver
33-
from django.utils.translation import gettext_lazy as _
34-
3534
auditLogger = logging.getLogger(__name__ + ".audit")
3635

3736
# Sender will be equal to the form that was completed

oioioi/base/permissions.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,20 @@ def __call__(self, *args, **kwargs):
4444
def __or__(self, other):
4545
if not isinstance(other, Condition):
4646
return NotImplemented
47-
condition_or = lambda *args, **kwargs: self(*args, **kwargs) or other(
48-
*args, **kwargs
49-
)
47+
def condition_or(*args, **kwargs):
48+
return self(*args, **kwargs) or other(*args, **kwargs)
5049
return Condition(condition_or)
5150

5251
def __and__(self, other):
5352
if not isinstance(other, Condition):
5453
return NotImplemented
55-
condition_and = lambda *args, **kwargs: self(*args, **kwargs) and other(
56-
*args, **kwargs
57-
)
54+
def condition_and(*args, **kwargs):
55+
return self(*args, **kwargs) and other(*args, **kwargs)
5856
return Condition(condition_and)
5957

6058
def __invert__(self):
61-
condition_inverted = lambda *args, **kwargs: not self(*args, **kwargs)
59+
def condition_inverted(*args, **kwargs):
60+
return not self(*args, **kwargs)
6261
return Condition(condition_inverted)
6362

6463

oioioi/base/tests/tests.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,23 +1210,23 @@ def setUp(self):
12101210
self.url_edit_profile = reverse('edit_profile')
12111211

12121212
def test_message(self):
1213-
for l in self.invalid_logins:
1214-
self.user.username = l
1213+
for valid_login in self.invalid_logins:
1214+
self.user.username = valid_login
12151215
self.user.save()
12161216

12171217
response = self.client.get(self.url_index, follow=True)
12181218
self.assertContains(response, 'contains forbidden characters')
12191219

1220-
for l in self.valid_logins:
1221-
self.user.username = l
1220+
for valid_login in self.valid_logins:
1221+
self.user.username = valid_login
12221222
self.user.save()
12231223

12241224
response = self.client.get(self.url_index, follow=True)
12251225
self.assertNotContains(response, 'contains forbidden characters')
12261226

12271227
def test_can_change_login_from_invalid(self):
1228-
for l in self.invalid_logins:
1229-
self.user.username = l
1228+
for invalid_login in self.invalid_logins:
1229+
self.user.username = invalid_login
12301230
self.user.save()
12311231

12321232
response = self.client.get(self.url_edit_profile)
@@ -1235,7 +1235,7 @@ def test_can_change_login_from_invalid(self):
12351235
response,
12361236
'<input type="text" id="id_username" name="username" '
12371237
'value="%s" class="form-control" '
1238-
'maxlength="150" required />' % l,
1238+
'maxlength="150" required />' % invalid_login,
12391239
html=True,
12401240
)
12411241

@@ -1248,7 +1248,7 @@ def test_can_change_login_from_invalid(self):
12481248
},
12491249
follow=True,
12501250
)
1251-
self.assertEqual(self.user.username, l)
1251+
self.assertEqual(self.user.username, invalid_login)
12521252

12531253
response = self.client.post(self.url_index, follow=True)
12541254
self.assertNotContains(response, 'contains not allowed characters')
@@ -1263,16 +1263,16 @@ def test_can_change_login_from_invalid(self):
12631263
)
12641264

12651265
def test_login_cannot_change_from_valid(self):
1266-
for l in self.valid_logins:
1267-
self.user.username = l
1266+
for valid_login in self.valid_logins:
1267+
self.user.username = valid_login
12681268
self.user.save()
12691269

12701270
response = self.client.get(self.url_edit_profile)
12711271
self.assertContains(
12721272
response,
12731273
'<input type="text" id="id_username" name="username" '
12741274
'value="%s" class="form-control" '
1275-
'maxlength="150" readonly required />' % l,
1275+
'maxlength="150" readonly required />' % valid_login,
12761276
html=True,
12771277
)
12781278

@@ -1281,7 +1281,7 @@ def test_login_cannot_change_from_valid(self):
12811281
{'username': 'valid_user', 'terms_accepted': True},
12821282
follow=True,
12831283
)
1284-
self.assertEqual(self.user.username, l)
1284+
self.assertEqual(self.user.username, valid_login)
12851285
self.assertContains(response, 'You cannot change your username.')
12861286

12871287
response = self.client.get(self.url_index, follow=True)
@@ -1296,9 +1296,9 @@ def test_failed_login_change(self):
12961296
self.user.username = self.invalid_logins[0]
12971297
self.user.save()
12981298

1299-
for l in self.invalid_logins:
1299+
for invalid_login in self.invalid_logins:
13001300
self.client.post(
1301-
url_edit_profile, {'username': l, 'terms_accepted': True}, follow=True
1301+
url_edit_profile, {'username': invalid_login, 'terms_accepted': True}, follow=True
13021302
)
13031303
self.assertEqual(self.user.username, self.invalid_logins[0])
13041304

oioioi/base/utils/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,8 @@ def strip_num_or_hash(filename):
506506

507507

508508
def naturalsort_key(key):
509-
convert = lambda text: int(text) if text.isdigit() else text
509+
def convert(text):
510+
return int(text) if text.isdigit() else text
510511
return [convert(c) for c in re.split('([0-9]+)', key)]
511512

512513

oioioi/contestexcl/middleware.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ def _default_selector(user, contest):
5656
if selector is None:
5757
final_selector = _default_selector
5858
else:
59-
final_selector = lambda user, contest: _default_selector(
60-
user, contest
61-
) and selector(user, contest)
59+
def final_selector(user, contest):
60+
return _default_selector(user, contest) and selector(user, contest)
6261

6362
if settings.ONLY_DEFAULT_CONTEST:
6463
qs = [Contest.objects.get(id=settings.DEFAULT_CONTEST)]

oioioi/contests/date_registration.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,24 @@ def decorator(original_class):
5353
)
5454
return original_class
5555

56+
def none_returner(obj):
57+
return None
58+
59+
def default_name_generator(obj):
60+
return str(model._meta.verbose_name) + " " + str(model._meta.get_field(date_field).verbose_name)
61+
5662
if model is None:
5763
return decorator
5864

5965
if name_generator is None:
60-
name_generator = (
61-
lambda obj: str(model._meta.verbose_name)
62-
+ " "
63-
+ str(model._meta.get_field(date_field).verbose_name)
64-
)
66+
name_generator = default_name_generator
6567

6668
if round_chooser is None:
67-
round_chooser = lambda obj: None
69+
round_chooser = none_returner
6870

6971
if qs_filter is None:
70-
qs_filter = lambda qs, contest_id: qs.filter(contest=contest_id)
72+
def qs_filter(qs, contest_id):
73+
return qs.filter(contest=contest_id)
7174

7275
date_item = self.DateItem(
7376
date_field, name_generator, round_chooser, qs_filter, model

oioioi/contests/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ def contest_links_generator(request):
739739
for link in links:
740740
# pylint: disable=cell-var-from-loop
741741
# http://docs.python-guide.org/en/latest/writing/gotchas/#late-binding-closures
742-
url_generator = lambda request, url=link.url: url
742+
url_generator = lambda request, url=link.url: url # noqa: E731
743743
item = MenuItem(
744744
name='contest_link_%d' % link.id,
745745
text=link.description,

oioioi/contests/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ def make_patterns(neutrals=None, contests=None, noncontests=None, globs=None):
5959
# namespaced with 'contest' or 'noncontest', we have to extract
6060
# and add them to our patterns so they are taken into account.
6161
def glob_namespaced_patterns(namespace):
62-
pattern_lists = [l for l in globs if getattr(l, 'namespace', None) == namespace]
63-
return [pattern for l in pattern_lists for pattern in l.url_patterns]
62+
pattern_lists = [glob for glob in globs if getattr(glob, 'namespace', None) == namespace]
63+
return [pattern for pattern_list in pattern_lists for pattern in pattern_list.url_patterns]
6464

6565
neutrals = neutrals or []
6666
contests = (contests or []) + neutrals + glob_namespaced_patterns('contest')

oioioi/default_settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from django.utils.translation import gettext_lazy as _
1313

1414
import oioioi
15+
from oioioi.contests.current_contest import ContestMode
1516

1617
INSTALLATION_CONFIG_VERSION = 49
1718

@@ -43,8 +44,8 @@
4344
'NAME': os.getenv('OIOIOI_DB_NAME', 'oioioi'), # Or path to database file if using sqlite3.
4445
'USER': os.getenv('OIOIOI_DB_USER', 'oioioi'), # Not used with sqlite3.
4546
'PASSWORD': os.getenv('OIOIOI_DB_PASSWORD', 'password'), # Not used with sqlite3.
46-
'HOST': os.getenv('OIOIOI_DB_HOST', 'db'), # Set to empty string for localhost. Not used with sqlite3.
47-
'PORT': os.getenv('OIOIOI_DB_PORT', ''), # Set to empty string for default. Not used with sqlite3.
47+
'HOST': os.getenv('OIOIOI_DB_HOST', 'db'), # Set to empty string for localhost. Not used with sqlite3.
48+
'PORT': os.getenv('OIOIOI_DB_PORT', ''), # Set to empty string for default. Not used with sqlite3.
4849
'ATOMIC_REQUESTS': True, # Don't touch unless you know what you're doing.
4950
}
5051
}
@@ -591,7 +592,6 @@
591592
#
592593
# Some features may depend on this setting, e.g. the "portals" app requires
593594
# that either the "neutral" or the "contest_if_possible" option is picked.
594-
from oioioi.contests.current_contest import ContestMode
595595
CONTEST_MODE = ContestMode.contest_if_possible
596596

597597
# A sample logging configuration. The only tangible logging

0 commit comments

Comments
 (0)