Skip to content

Commit 679f3d7

Browse files
committed
Rename method.
1 parent d0c0d3f commit 679f3d7

File tree

7 files changed

+17
-19
lines changed

7 files changed

+17
-19
lines changed

django_mongodb_backend/expressions/builtins.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@
3030

3131

3232
def base_expression(self, compiler, connection, as_path=False, **extra):
33-
if (
34-
as_path
35-
and hasattr(self, "as_mql_path")
36-
and getattr(self, "is_simple_expression", lambda: False)()
37-
):
33+
if as_path and hasattr(self, "as_mql_path") and getattr(self, "can_use_path", False):
3834
return self.as_mql_path(compiler, connection, **extra)
3935

4036
expr = self.as_mql_expr(compiler, connection, **extra)

django_mongodb_backend/fields/array.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ def __init__(self, index, base_field, *args, **kwargs):
381381
self.index = index
382382
self.base_field = base_field
383383

384-
def is_simple_expression(self):
384+
@property
385+
def can_use_path(self):
385386
return self.is_simple_column
386387

387388
@property

django_mongodb_backend/fields/embedded_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ def __init__(self, key_name, ref_field, *args, **kwargs):
166166
def get_lookup(self, name):
167167
return self.ref_field.get_lookup(name)
168168

169-
def is_simple_expression(self):
169+
@property
170+
def can_use_path(self):
170171
return self.is_simple_column
171172

172173
@cached_property

django_mongodb_backend/fields/embedded_model_array.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ def __call__(self, this, *args, **kwargs):
248248
self._lhs = self._sub_transform(self._lhs, *args, **kwargs)
249249
return self
250250

251-
def is_simple_expression(self):
251+
@property
252+
def can_use_path(self):
252253
return self.is_simple_column
253254

254255
@cached_property

django_mongodb_backend/fields/json.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def _has_key_predicate(path, root_column=None, negated=False, as_path=False):
7272
return result
7373

7474

75+
@property
7576
def has_key_check_simple_expression(self):
7677
rhs = [self.rhs] if not isinstance(self.rhs, (list, tuple)) else self.rhs
7778
return self.is_simple_column and all(key.isalnum() for key in rhs)
@@ -147,7 +148,7 @@ def key_transform_in(self, compiler, connection, as_path=False):
147148
Return MQL to check if a JSON path exists and that its values are in the
148149
set of specified values (rhs).
149150
"""
150-
if as_path and self.is_simple_expression():
151+
if as_path and self.can_use_path():
151152
return builtin_lookup_path(self, compiler, connection)
152153

153154
lhs_mql = process_lhs(self, compiler, connection)
@@ -226,6 +227,7 @@ def key_transform_numeric_lookup_mixin_path(self, compiler, connection):
226227
return builtin_lookup_path(self, compiler, connection)
227228

228229

230+
@property
229231
def keytransform_is_simple_column(self):
230232
previous = self
231233
while isinstance(previous, KeyTransform):
@@ -242,11 +244,11 @@ def register_json_field():
242244
HasKey.mongo_operator = None
243245
HasKeyLookup.as_mql_path = partialmethod(has_key_lookup, as_path=True)
244246
HasKeyLookup.as_mql_expr = partialmethod(has_key_lookup, as_path=False)
245-
HasKeyLookup.is_simple_expression = has_key_check_simple_expression
247+
HasKeyLookup.can_use_path = has_key_check_simple_expression
246248
HasKeys.mongo_operator = "$and"
247249
JSONExact.process_rhs = json_exact_process_rhs
248-
KeyTransform.is_simple_column = property(keytransform_is_simple_column)
249-
KeyTransform.is_simple_expression = keytransform_is_simple_column
250+
KeyTransform.is_simple_column = keytransform_is_simple_column
251+
KeyTransform.can_use_path = keytransform_is_simple_column
250252
KeyTransform.as_mql_path = partialmethod(key_transform, as_path=True)
251253
KeyTransform.as_mql_expr = partialmethod(key_transform, as_path=False)
252254
KeyTransformExact.as_mql_expr = key_transform_exact_expr

django_mongodb_backend/functions.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,6 @@ def trunc_time(self, compiler, connection):
292292
}
293293

294294

295-
def is_simple_expression(self): # noqa: ARG001
296-
return False
297-
298-
299295
def register_functions():
300296
Cast.as_mql_expr = cast
301297
Concat.as_mql_expr = concat
@@ -323,4 +319,4 @@ def register_functions():
323319
TruncDate.as_mql_expr = trunc_date
324320
TruncTime.as_mql_expr = trunc_time
325321
Upper.as_mql_expr = preserve_null("toUpper")
326-
Func.is_simple_expression = is_simple_expression
322+
Func.can_use_path = False

django_mongodb_backend/lookups.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,15 @@ def uuid_text_mixin(self, compiler, connection): # noqa: ARG001
138138
raise NotSupportedError("Pattern lookups on UUIDField are not supported.")
139139

140140

141-
def is_simple_expression(self):
141+
@property
142+
def can_use_path(self):
142143
simple_column = getattr(self.lhs, "is_simple_column", False)
143144
constant_value = is_constant_value(self.rhs)
144145
return simple_column and constant_value
145146

146147

147148
def register_lookups():
148-
Lookup.is_simple_expression = is_simple_expression
149+
Lookup.can_use_path = can_use_path
149150
BuiltinLookup.as_mql_path = builtin_lookup_path
150151
BuiltinLookup.as_mql_expr = builtin_lookup_expr
151152
FieldGetDbPrepValueIterableMixin.resolve_expression_parameter = (

0 commit comments

Comments
 (0)