Skip to content

Commit

Permalink
Address pylint finding
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHammond13 committed Aug 15, 2023
1 parent 1541c5f commit 6fe54f7
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions caracara_filters/validators/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,41 @@ def options_validator(options: List[Any], chosen_option: Any, case_sensitive: bo
Technically, we should probably test whether this item is multivariate here. However, we
perform that check in fql.py within the FQLGenerator function.
"""
if case_sensitive:
if isinstance(chosen_option, list):
for chosen_option_item in chosen_option:
if chosen_option_item not in options:
return False
return True
return chosen_option in options
Scenarios to cover here:
- Case sensitive and a list of strings
- Case sensitive and a list of non-strings
- Case sensitive and a string
- Non-case sensitive and a list of strings
- Non-case sensitive and a list of non-strings
- Non-case sensitive and a string
"""
if isinstance(chosen_option, str):
return chosen_option in options if case_sensitive \
else chosen_option.lower() in options

# If we got this far, case sensitivity is off
if isinstance(chosen_option, list):
for chosen_option_item in chosen_option:
if isinstance(chosen_option_item, str):
if chosen_option_item.lower() not in options:
return False
else:
if chosen_option_item not in options:
return False
if (
isinstance(chosen_option_item, str) and
case_sensitive and
chosen_option_item not in options
):
return False

if (
isinstance(chosen_option_item, str) and
not case_sensitive and
chosen_option_item.lower() not in options
):
return False

if (
not isinstance(chosen_option_item, str) and
chosen_option_item not in options
):
return False

return True

if isinstance(chosen_option, str):
return chosen_option.lower() in options
else:
return chosen_option in options
return chosen_option in options

0 comments on commit 6fe54f7

Please sign in to comment.