@@ -117,7 +117,7 @@ def is_supported_container_type(typ: Optional[type]) -> bool:
117
117
118
118
119
119
def validate_model_fields (model : Type ["RedisModel" ], field_values : Dict [str , Any ]):
120
- for field_name in field_values . keys () :
120
+ for field_name in field_values :
121
121
if "__" in field_name :
122
122
obj = model
123
123
for sub_field in field_name .split ("__" ):
@@ -432,11 +432,11 @@ def validate_sort_fields(self, sort_fields: List[str]):
432
432
433
433
@staticmethod
434
434
def resolve_field_type (field : ModelField , op : Operators ) -> RediSearchFieldTypes :
435
- if getattr (field .field_info , "primary_key" , None ) is True :
435
+ if getattr (field .field_info , "primary_key" , None ):
436
436
return RediSearchFieldTypes .TAG
437
437
elif op is Operators .LIKE :
438
438
fts = getattr (field .field_info , "full_text_search" , None )
439
- if fts is not True : # Could be PydanticUndefined
439
+ if not fts : # Could be PydanticUndefined
440
440
raise QuerySyntaxError (
441
441
f"You tried to do a full-text search on the field '{ field .name } ', "
442
442
f"but the field is not indexed for full-text search. Use the "
@@ -464,7 +464,7 @@ def resolve_field_type(field: ModelField, op: Operators) -> RediSearchFieldTypes
464
464
# is not itself directly indexed, but instead, we index any fields
465
465
# within the model inside the list marked as `index=True`.
466
466
return RediSearchFieldTypes .TAG
467
- elif container_type is not None :
467
+ elif container_type :
468
468
raise QuerySyntaxError (
469
469
"Only lists and tuples are supported for multi-value fields. "
470
470
f"Docs: { ERRORS_URL } #E4"
@@ -567,7 +567,7 @@ def resolve_value(
567
567
# The value contains the TAG field separator. We can work
568
568
# around this by breaking apart the values and unioning them
569
569
# with multiple field:{} queries.
570
- values : filter = filter ( None , value .split (separator_char ))
570
+ values : List [ str ] = [ val for val in value .split (separator_char ) if val ]
571
571
for value in values :
572
572
value = escaper .escape (value )
573
573
result += f"@{ field_name } :{{{ value } }}"
@@ -1131,7 +1131,7 @@ async def save(self, pipeline: Optional[Pipeline] = None) -> "RedisModel":
1131
1131
raise NotImplementedError
1132
1132
1133
1133
async def expire (self , num_seconds : int , pipeline : Optional [Pipeline ] = None ):
1134
- if pipeline is None :
1134
+ if not pipeline :
1135
1135
db = self .db ()
1136
1136
else :
1137
1137
db = pipeline
@@ -1195,12 +1195,12 @@ def to_string(s):
1195
1195
step = 2 # Because the result has content
1196
1196
offset = 1 # The first item is the count of total matches.
1197
1197
1198
- for i in xrange (1 , len (res ), step ):
1198
+ for i in range (1 , len (res ), step ):
1199
1199
fields_offset = offset
1200
1200
1201
1201
fields = dict (
1202
1202
dict (
1203
- izip (
1203
+ zip (
1204
1204
map (to_string , res [i + fields_offset ][::2 ]),
1205
1205
map (to_string , res [i + fields_offset ][1 ::2 ]),
1206
1206
)
@@ -1244,7 +1244,7 @@ async def add(
1244
1244
pipeline : Optional [Pipeline ] = None ,
1245
1245
pipeline_verifier : Callable [..., Any ] = verify_pipeline_response ,
1246
1246
) -> Sequence ["RedisModel" ]:
1247
- if pipeline is None :
1247
+ if not pipeline :
1248
1248
# By default, send commands in a pipeline. Saving each model will
1249
1249
# be atomic, but Redis may process other commands in between
1250
1250
# these saves.
@@ -1261,7 +1261,7 @@ async def add(
1261
1261
1262
1262
# If the user didn't give us a pipeline, then we need to execute
1263
1263
# the one we just created.
1264
- if pipeline is None :
1264
+ if not pipeline :
1265
1265
result = await db .execute ()
1266
1266
pipeline_verifier (result , expected_responses = len (models ))
1267
1267
@@ -1303,7 +1303,7 @@ def __init_subclass__(cls, **kwargs):
1303
1303
1304
1304
async def save (self , pipeline : Optional [Pipeline ] = None ) -> "HashModel" :
1305
1305
self .check ()
1306
- if pipeline is None :
1306
+ if not pipeline :
1307
1307
db = self .db ()
1308
1308
else :
1309
1309
db = pipeline
@@ -1356,7 +1356,7 @@ def _get_value(cls, *args, **kwargs) -> Any:
1356
1356
values. Is there a better way?
1357
1357
"""
1358
1358
val = super ()._get_value (* args , ** kwargs )
1359
- if val is None :
1359
+ if not val :
1360
1360
return ""
1361
1361
return val
1362
1362
@@ -1392,7 +1392,7 @@ def schema_for_fields(cls):
1392
1392
name , _type , field .field_info
1393
1393
)
1394
1394
schema_parts .append (redisearch_field )
1395
- elif getattr (field .field_info , "index" , None ) is True :
1395
+ elif getattr (field .field_info , "index" , None ):
1396
1396
schema_parts .append (cls .schema_for_type (name , _type , field .field_info ))
1397
1397
elif is_subscripted_type :
1398
1398
# Ignore subscripted types (usually containers!) that we don't
@@ -1437,7 +1437,7 @@ def schema_for_type(cls, name, typ: Any, field_info: PydanticFieldInfo):
1437
1437
elif any (issubclass (typ , t ) for t in NUMERIC_TYPES ):
1438
1438
schema = f"{ name } NUMERIC"
1439
1439
elif issubclass (typ , str ):
1440
- if getattr (field_info , "full_text_search" , False ) is True :
1440
+ if getattr (field_info , "full_text_search" , False ):
1441
1441
schema = (
1442
1442
f"{ name } TAG SEPARATOR { SINGLE_VALUE_TAG_FIELD_SEPARATOR } "
1443
1443
f"{ name } AS { name } _fts TEXT"
@@ -1455,7 +1455,7 @@ def schema_for_type(cls, name, typ: Any, field_info: PydanticFieldInfo):
1455
1455
schema = " " .join (sub_fields )
1456
1456
else :
1457
1457
schema = f"{ name } TAG SEPARATOR { SINGLE_VALUE_TAG_FIELD_SEPARATOR } "
1458
- if schema and sortable is True :
1458
+ if schema and sortable :
1459
1459
schema += " SORTABLE"
1460
1460
return schema
1461
1461
@@ -1475,7 +1475,7 @@ def __init__(self, *args, **kwargs):
1475
1475
1476
1476
async def save (self , pipeline : Optional [Pipeline ] = None ) -> "JsonModel" :
1477
1477
self .check ()
1478
- if pipeline is None :
1478
+ if not pipeline :
1479
1479
db = self .db ()
1480
1480
else :
1481
1481
db = pipeline
@@ -1633,7 +1633,7 @@ def schema_for_type(
1633
1633
parent_type = typ ,
1634
1634
)
1635
1635
)
1636
- return " " .join (filter ( None , sub_fields ) )
1636
+ return " " .join ([ sub_field for sub_field in sub_fields if sub_field ] )
1637
1637
# NOTE: This is the termination point for recursion. We've descended
1638
1638
# into models and lists until we found an actual value to index.
1639
1639
elif should_index :
@@ -1655,28 +1655,28 @@ def schema_for_type(
1655
1655
1656
1656
# TODO: GEO field
1657
1657
if parent_is_container_type or parent_is_model_in_container :
1658
- if typ is not str :
1658
+ if not isinstance ( typ , str ) :
1659
1659
raise RedisModelError (
1660
1660
"In this Preview release, list and tuple fields can only "
1661
1661
f"contain strings. Problem field: { name } . See docs: TODO"
1662
1662
)
1663
- if full_text_search is True :
1663
+ if full_text_search :
1664
1664
raise RedisModelError (
1665
1665
"List and tuple fields cannot be indexed for full-text "
1666
1666
f"search. Problem field: { name } . See docs: TODO"
1667
1667
)
1668
1668
schema = f"{ path } AS { index_field_name } TAG SEPARATOR { SINGLE_VALUE_TAG_FIELD_SEPARATOR } "
1669
- if sortable is True :
1669
+ if sortable :
1670
1670
raise sortable_tag_error
1671
1671
elif any (issubclass (typ , t ) for t in NUMERIC_TYPES ):
1672
1672
schema = f"{ path } AS { index_field_name } NUMERIC"
1673
1673
elif issubclass (typ , str ):
1674
- if full_text_search is True :
1674
+ if full_text_search :
1675
1675
schema = (
1676
1676
f"{ path } AS { index_field_name } TAG SEPARATOR { SINGLE_VALUE_TAG_FIELD_SEPARATOR } "
1677
1677
f"{ path } AS { index_field_name } _fts TEXT"
1678
1678
)
1679
- if sortable is True :
1679
+ if sortable :
1680
1680
# NOTE: With the current preview release, making a field
1681
1681
# full-text searchable and sortable only makes the TEXT
1682
1682
# field sortable. This means that results for full-text
@@ -1685,11 +1685,11 @@ def schema_for_type(
1685
1685
schema += " SORTABLE"
1686
1686
else :
1687
1687
schema = f"{ path } AS { index_field_name } TAG SEPARATOR { SINGLE_VALUE_TAG_FIELD_SEPARATOR } "
1688
- if sortable is True :
1688
+ if sortable :
1689
1689
raise sortable_tag_error
1690
1690
else :
1691
1691
schema = f"{ path } AS { index_field_name } TAG SEPARATOR { SINGLE_VALUE_TAG_FIELD_SEPARATOR } "
1692
- if sortable is True :
1692
+ if sortable :
1693
1693
raise sortable_tag_error
1694
1694
return schema
1695
1695
return ""
0 commit comments