Replace inline if statements with or

example: (x = something if (x is None) else x ) --> (x = x or something)
This commit is contained in:
AliRn 2022-03-05 12:38:04 +03:30
parent efc7c1d664
commit 06040c4d26
4 changed files with 5 additions and 6 deletions

View File

@ -18,7 +18,7 @@ def api_view(http_method_names=None):
Decorator that converts a function-based view into an APIView subclass.
Takes a list of allowed methods for the view as an argument.
"""
http_method_names = ['GET'] if (http_method_names is None) else http_method_names
http_method_names = http_method_names or ['GET']
def decorator(func):
@ -142,8 +142,7 @@ def action(methods=None, detail=None, url_path=None, url_name=None, **kwargs):
how the `@renderer_classes` etc. decorators work for function-
based API views.
"""
methods = ['get'] if methods is None else methods
methods = [method.lower() for method in methods]
methods = [method.lower() for method in methods or ['get']]
assert detail is not None, (
"@action() missing required argument: 'detail'"

View File

@ -345,7 +345,7 @@ class Field:
self.initial = self.initial if (initial is empty) else initial
self.label = label
self.help_text = help_text
self.style = {} if style is None else style
self.style = style or {}
self.allow_null = allow_null
if self.default_empty_html is not empty:

View File

@ -45,7 +45,7 @@ def order_by_precedence(media_type_lst):
class _MediaType:
def __init__(self, media_type_str):
self.orig = '' if (media_type_str is None) else media_type_str
self.orig = media_type_str or ''
self.full_type, self.params = parse_header(self.orig.encode(HTTP_HEADER_ENCODING))
self.main_type, sep, self.sub_type = self.full_type.partition('/')

View File

@ -81,7 +81,7 @@ class URLPathVersioning(BaseVersioning):
def reverse(self, viewname, args=None, kwargs=None, request=None, format=None, **extra):
if request.version is not None:
kwargs = {} if (kwargs is None) else kwargs
kwargs = kwargs or {}
kwargs[self.version_param] = request.version
return super().reverse(