Skip to content

Commit

Permalink
Shorten ifs using membership logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Patryk Szczepański committed Jul 8, 2022
1 parent aa3425e commit b187eaf
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions xapian_backend.py
Expand Up @@ -130,7 +130,7 @@ def __call__(self, begin, end):
begin = -sys.maxsize - 1
elif field_type == 'float':
begin = float('-inf')
elif field_type == 'date' or field_type == 'datetime':
elif field_type in ['date', 'datetime']:
begin = '00010101000000'
elif end == '*':
if field_type == 'text':
Expand All @@ -139,7 +139,7 @@ def __call__(self, begin, end):
end = sys.maxsize
elif field_type == 'float':
end = float('inf')
elif field_type == 'date' or field_type == 'datetime':
elif field_type in ['date', 'datetime']:
end = '99990101000000'

if field_type == 'float':
Expand Down Expand Up @@ -1612,7 +1612,7 @@ def strf(dt):
value = INTEGER_FORMAT % term
elif field_type == 'float':
value = xapian.sortable_serialise(term)
elif field_type == 'date' or field_type == 'datetime':
elif field_type in ['date', 'datetime']:
if field_type == 'date':
# http://stackoverflow.com/a/1937636/931303 and comments
term = datetime.datetime.combine(term, datetime.time())
Expand Down Expand Up @@ -1650,7 +1650,7 @@ def _from_xapian_value(value, field_type):
return int(value)
elif field_type == 'float':
return xapian.sortable_unserialise(value)
elif field_type == 'date' or field_type == 'datetime':
elif field_type in ['date', 'datetime']:
datetime_value = datetime.datetime.strptime(value, DATETIME_FORMAT)
if field_type == 'datetime':
return datetime_value
Expand Down

0 comments on commit b187eaf

Please sign in to comment.