Skip to content

Commit bc62db1

Browse files
committed
LITE-27567 Add black
* Double quotes replaced with single quotes
1 parent 77be154 commit bc62db1

30 files changed

+1390
-886
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,9 @@ Development
275275
1. Python 3.8+
276276
2. Install poetry: `pip install poetry`
277277
3. Install dependencies: `poetry install`
278-
4. We use `isort` library to order and format our imports, and we check it using `flake8-isort` library (automatically on `flake8` run).
279-
For convenience you may run `isort .` to order imports.
278+
4. We use `isort` library to order and format our imports, and `black` - to format the code.
279+
We check it using `flake8-isort` and `flake8-black` libraries (automatically on `flake8` run).
280+
For convenience you may run `isort . && black .` to format the code.
280281
5. Run flake8: `poetry run flake8`
281282

282283
Testing

dj_rql/_dataclasses.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ def __init__(self, queryset, select_data, filter_tree, filter_node=None, filter_
2121

2222

2323
class FilterArgs:
24-
def __init__(self, filter_name, operator, str_value, list_operator=None,
25-
namespace=None, **kwargs):
24+
def __init__(
25+
self, filter_name, operator, str_value, list_operator=None, namespace=None, **kwargs
26+
):
2627
"""
2728
:param str filter_name: Full filter name (f.e. ns1.ns2.filter1)
2829
:param str operator: RQL operator (f.e. eq, like, etc.)

dj_rql/constants.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class FilterTypes(FT):
4848
def field_filter_type(cls, field):
4949
return next(
5050
(
51-
filter_type for base_cls, filter_type in cls.mapper
51+
filter_type
52+
for base_cls, filter_type in cls.mapper
5253
if issubclass(field.__class__, base_cls)
5354
),
5455
cls.STRING,

dj_rql/drf/backend.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def get_rql_filter_class(self):
4646
return ModelFilterClass
4747
```
4848
"""
49+
4950
OPENAPI_RETRIEVE_SPECIFICATION = False
5051

5152
_CACHES = {}
@@ -59,11 +60,13 @@ def filter_queryset(self, request, queryset, view):
5960
filter_instance = self._get_filter_instance(filter_class, queryset, view)
6061
query = self.get_query(filter_instance, request, view)
6162

62-
can_query_be_cached = all((
63-
filter_class.QUERIES_CACHE_BACKEND,
64-
filter_class.QUERIES_CACHE_SIZE,
65-
request.method in ('GET', 'HEAD', 'OPTIONS'),
66-
))
63+
can_query_be_cached = all(
64+
(
65+
filter_class.QUERIES_CACHE_BACKEND,
66+
filter_class.QUERIES_CACHE_SIZE,
67+
request.method in ('GET', 'HEAD', 'OPTIONS'),
68+
),
69+
)
6770
if can_query_be_cached:
6871
# We must use the combination of queryset and query to make a cache key as
6972
# queryset can already contain some filters (e.x. based on authentication)
@@ -117,7 +120,8 @@ def get_query(cls, filter_instance, request, view):
117120
def _get_or_init_cache(cls, filter_class, view):
118121
qual_name = cls._get_filter_cls_qual_name(view, filter_class)
119122
return cls._CACHES.setdefault(
120-
qual_name, filter_class.QUERIES_CACHE_BACKEND(int(filter_class.QUERIES_CACHE_SIZE)),
123+
qual_name,
124+
filter_class.QUERIES_CACHE_BACKEND(int(filter_class.QUERIES_CACHE_SIZE)),
121125
)
122126

123127
@classmethod
@@ -135,6 +139,8 @@ def _get_filter_instance(cls, filter_class, queryset, view):
135139
@staticmethod
136140
def _get_filter_cls_qual_name(view, filter_class):
137141
return '{0}.{1}+{2}.{3}'.format(
138-
view.__class__.__module__, view.__class__.__name__,
139-
filter_class.__module__, filter_class.__name__,
142+
view.__class__.__module__,
143+
view.__class__.__name__,
144+
filter_class.__module__,
145+
filter_class.__name__,
140146
)

dj_rql/drf/compat.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class CompatibilityRQLFilterBackend(RQLFilterBackend):
2828
filter backend (without raising API version number or losing compatibility), this base
2929
compatibility DRF backend must be inherited from.
3030
"""
31+
3132
@classmethod
3233
def get_query(cls, filter_instance, request, view):
3334
try:
@@ -70,6 +71,7 @@ class DjangoFiltersRQLFilterBackend(CompatibilityRQLFilterBackend):
7071
* ?&& syntax in queries;
7172
* etc.
7273
"""
74+
7375
RESERVED_ORDERING_WORDS = {'order_by', 'ordering'}
7476

7577
_POSSIBLE_DF_LOOKUPS = DJL.all()
@@ -161,7 +163,9 @@ def get_rql_query(cls, filter_instance, request, query_string):
161163
one_filter_value_pairs = []
162164
for value in request.query_params.getlist(filter_name):
163165
name_value_pair = cls._get_one_filter_value_pair(
164-
filter_instance, filter_name, value,
166+
filter_instance,
167+
filter_name,
168+
value,
165169
)
166170
if name_value_pair is not None:
167171
one_filter_value_pairs.append(name_value_pair)
@@ -202,7 +206,8 @@ def _convert_filter_to_rql(cls, filter_name, value):
202206

203207
if lookup == DJL.IN:
204208
return 'in({0},({1}))'.format(
205-
filter_base, ','.join(cls._add_quotes_to_value(v) for v in value.split(',') if v),
209+
filter_base,
210+
','.join(cls._add_quotes_to_value(v) for v in value.split(',') if v),
206211
)
207212

208213
if lookup == DJL.NULL:

dj_rql/drf/paginations.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
class RQLLimitOffsetPagination(LimitOffsetPagination):
16-
""" RQL limit offset pagination. """
16+
"""RQL limit offset pagination."""
1717

1818
def __init__(self, *args, **kwargs):
1919
super(RQLLimitOffsetPagination, self).__init__(*args, **kwargs)
@@ -37,9 +37,11 @@ def paginate_queryset(self, queryset, request, view=None):
3737
try:
3838
self._rql_limit, self._rql_offset = RQLLimitOffsetTransformer().transform(rql_ast)
3939
except LarkError:
40-
raise RQLFilterParsingError(details={
41-
'error': 'Limit and offset are set incorrectly.',
42-
})
40+
raise RQLFilterParsingError(
41+
details={
42+
'error': 'Limit and offset are set incorrectly.',
43+
},
44+
)
4345

4446
self.limit = self.get_limit(request)
4547
if self.limit == 0:
@@ -62,7 +64,7 @@ def paginate_queryset(self, queryset, request, view=None):
6264
if self.limit + self.offset > self.count:
6365
self.limit = self.count - self.offset
6466

65-
return list(queryset[self.offset:self.offset + self.limit])
67+
return list(queryset[self.offset : self.offset + self.limit])
6668

6769
def get_limit(self, *args):
6870
if self._rql_limit is not None:
@@ -82,7 +84,7 @@ def get_offset(self, *args):
8284

8385

8486
class RQLContentRangeLimitOffsetPagination(RQLLimitOffsetPagination):
85-
""" RQL RFC2616 limit offset pagination.
87+
"""RQL RFC2616 limit offset pagination.
8688
8789
Examples:
8890
```
@@ -96,6 +98,8 @@ class RQLContentRangeLimitOffsetPagination(RQLLimitOffsetPagination):
9698
def get_paginated_response(self, data):
9799
length = len(data) - 1 if data else 0
98100
content_range = 'items {0}-{1}/{2}'.format(
99-
self.offset, self.offset + length, self.count,
101+
self.offset,
102+
self.offset + length,
103+
self.count,
100104
)
101105
return Response(data, headers={'Content-Range': content_range})

dj_rql/drf/serializers.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def apply_rql_select(self):
1919

2020
for field_name, is_included in rql_select['select'].items():
2121
split_field_name = field_name.split('.')
22-
is_current_level_field = (len(split_field_name) == 1)
22+
is_current_level_field = len(split_field_name) == 1
2323
current_depth_field_name = split_field_name[0]
2424

2525
if is_current_level_field:
@@ -48,8 +48,11 @@ def _get_deeper_rql_select(self):
4848

4949
def _get_field_rql_select(self, field):
5050
take_parent = bool(
51-
field.parent and getattr(field.parent, 'many', False) and isinstance(
52-
field, field.parent.child.__class__,
51+
field.parent
52+
and getattr(field.parent, 'many', False)
53+
and isinstance(
54+
field,
55+
field.parent.child.__class__,
5356
),
5457
)
5558
if take_parent:

0 commit comments

Comments
 (0)