Skip to content

Commit ca7984a

Browse files
committed
remove: additional lint fixes
1 parent 84f6c26 commit ca7984a

File tree

2 files changed

+87
-87
lines changed

2 files changed

+87
-87
lines changed

optimizely/helpers/condition.py

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,9 @@ def semver_equal_evaluator(self, index):
423423
"""
424424
result = self.compare_user_version_with_target_version(index)
425425
if result is None:
426-
return result
426+
return None
427427

428-
return self.compare_user_version_with_target_version(index) == 0
428+
return result == 0
429429

430430
def semver_greater_than_evaluator(self, index):
431431
""" Evaluate the given semantic version greater than match target version for the user version.
@@ -442,8 +442,9 @@ def semver_greater_than_evaluator(self, index):
442442
"""
443443
result = self.compare_user_version_with_target_version(index)
444444
if result is None:
445-
return result
446-
return self.compare_user_version_with_target_version(index) > 0
445+
return None
446+
447+
return result > 0
447448

448449
def semver_less_than_evaluator(self, index):
449450
""" Evaluate the given semantic version less than match target version for the user version.
@@ -460,8 +461,9 @@ def semver_less_than_evaluator(self, index):
460461
"""
461462
result = self.compare_user_version_with_target_version(index)
462463
if result is None:
463-
return result
464-
return self.compare_user_version_with_target_version(index) < 0
464+
return None
465+
466+
return result < 0
465467

466468
def semver_less_than_or_equal_evaluator(self, index):
467469
""" Evaluate the given semantic version less than or equal to match target version for the user version.
@@ -478,8 +480,9 @@ def semver_less_than_or_equal_evaluator(self, index):
478480
"""
479481
result = self.compare_user_version_with_target_version(index)
480482
if result is None:
481-
return result
482-
return self.compare_user_version_with_target_version(index) <= 0
483+
return None
484+
485+
return result <= 0
483486

484487
def semver_greater_than_or_equal_evaluator(self, index):
485488
""" Evaluate the given semantic version greater than or equal to match target version for the user version.
@@ -496,22 +499,23 @@ def semver_greater_than_or_equal_evaluator(self, index):
496499
"""
497500
result = self.compare_user_version_with_target_version(index)
498501
if result is None:
499-
return result
500-
return self.compare_user_version_with_target_version(index) >= 0
502+
return None
503+
504+
return result >= 0
501505

502506
EVALUATORS_BY_MATCH_TYPE = {
503507
ConditionMatchTypes.EXACT: exact_evaluator,
504508
ConditionMatchTypes.EXISTS: exists_evaluator,
505509
ConditionMatchTypes.GREATER_THAN: greater_than_evaluator,
510+
ConditionMatchTypes.GREATER_THAN_OR_EQUAL: greater_than_or_equal_evaluator,
506511
ConditionMatchTypes.LESS_THAN: less_than_evaluator,
512+
ConditionMatchTypes.LESS_THAN_OR_EQUAL: less_than_or_equal_evaluator,
507513
ConditionMatchTypes.SEMVER_EQ: semver_equal_evaluator,
508514
ConditionMatchTypes.SEMVER_GE: semver_greater_than_or_equal_evaluator,
509515
ConditionMatchTypes.SEMVER_GT: semver_greater_than_evaluator,
510516
ConditionMatchTypes.SEMVER_LE: semver_less_than_or_equal_evaluator,
511517
ConditionMatchTypes.SEMVER_LT: semver_less_than_evaluator,
512-
ConditionMatchTypes.SUBSTRING: substring_evaluator,
513-
ConditionMatchTypes.LESS_THAN_OR_EQUAL: less_than_or_equal_evaluator,
514-
ConditionMatchTypes.GREATER_THAN_OR_EQUAL: greater_than_or_equal_evaluator,
518+
ConditionMatchTypes.SUBSTRING: substring_evaluator
515519
}
516520

517521
def split_semantic_version(self, target):
@@ -523,36 +527,34 @@ def split_semantic_version(self, target):
523527
Returns:
524528
List:
525529
- The array of version split into smaller parts i.e major, minor, patch etc
526-
Exception:
530+
None:
527531
- if the given version is invalid in format
528532
"""
529533
target_prefix = target
530534
target_suffix = ""
531535
target_parts = []
532536

533-
# remove spaces from target version string
534-
537+
# check that target shouldn't have white space
535538
if self.has_white_space(target):
536539
self.logger.warning(Errors.INVALID_ATTRIBUTE_FORMAT)
537540
return None
538541

539542
# check for pre release e.g. 1.0.0-alpha where 'alpha' is a pre release
540543
# otherwise check for build e.g. 1.0.0+001 where 001 is a build metadata
541-
542544
if self.is_pre_release(target):
543545
target_parts = target.split(SemverType.IS_PRE_RELEASE)
544546
elif self.is_build(target):
545547
target_parts = target.split(SemverType.IS_BUILD)
546548

547-
# validate target version into prefix and suffix
549+
# split target version into prefix and suffix
548550
if target_parts:
549551
if len(target_parts) < 1:
550552
self.logger.warning(Errors.INVALID_ATTRIBUTE_FORMAT)
551553
return None
552554
target_prefix = str(target_parts[0])
553555
target_suffix = target_parts[1:]
554556

555-
# validate dot counts in a target version
557+
# check dot counts in target_prefix
556558
dot_count = target_prefix.count(".")
557559
if dot_count > 2:
558560
self.logger.warning(Errors.INVALID_ATTRIBUTE_FORMAT)
@@ -575,15 +577,15 @@ def evaluate(self, index):
575577
""" Given a custom attribute audience condition and user attributes, evaluate the
576578
condition against the attributes.
577579
578-
Args:
579-
index: Index of the condition to be evaluated.
580+
Args:
581+
index: Index of the condition to be evaluated.
580582
581-
Returns:
582-
Boolean:
583-
- True if the user attributes match the given condition.
584-
- False if the user attributes don't match the given condition.
585-
None: if the user attributes and condition can't be evaluated.
586-
"""
583+
Returns:
584+
Boolean:
585+
- True if the user attributes match the given condition.
586+
- False if the user attributes don't match the given condition.
587+
None: if the user attributes and condition can't be evaluated.
588+
"""
587589

588590
if self.condition_data[index][2] != self.CUSTOM_ATTRIBUTE_CONDITION_TYPE:
589591
self.logger.warning(audience_logs.UNKNOWN_CONDITION_TYPE.format(self._get_condition_json(index)))
@@ -616,7 +618,7 @@ def evaluate(self, index):
616618

617619
class ConditionDecoder(object):
618620
""" Class which provides an object_hook method for decoding dict
619-
objects into a list when given a condition_decoder. """
621+
objects into a list when given a condition_decoder. """
620622

621623
def __init__(self, condition_decoder):
622624
self.condition_list = []
@@ -625,16 +627,16 @@ def __init__(self, condition_decoder):
625627

626628
def object_hook(self, object_dict):
627629
""" Hook which when passed into a json.JSONDecoder will replace each dict
628-
in a json string with its index and convert the dict to an object as defined
629-
by the passed in condition_decoder. The newly created condition object is
630-
appended to the conditions_list.
630+
in a json string with its index and convert the dict to an object as defined
631+
by the passed in condition_decoder. The newly created condition object is
632+
appended to the conditions_list.
631633
632-
Args:
633-
object_dict: Dict representing an object.
634+
Args:
635+
object_dict: Dict representing an object.
634636
635-
Returns:
636-
An index which will be used as the placeholder in the condition_structure
637-
"""
637+
Returns:
638+
An index which will be used as the placeholder in the condition_structure
639+
"""
638640
instance = self.decoder(object_dict)
639641
self.condition_list.append(instance)
640642
self.index += 1
@@ -644,12 +646,12 @@ def object_hook(self, object_dict):
644646
def _audience_condition_deserializer(obj_dict):
645647
""" Deserializer defining how dict objects need to be decoded for audience conditions.
646648
647-
Args:
648-
obj_dict: Dict representing one audience condition.
649+
Args:
650+
obj_dict: Dict representing one audience condition.
649651
650-
Returns:
651-
List consisting of condition key with corresponding value, type and match.
652-
"""
652+
Returns:
653+
List consisting of condition key with corresponding value, type and match.
654+
"""
653655
return [
654656
obj_dict.get('name'),
655657
obj_dict.get('value'),
@@ -660,16 +662,16 @@ def _audience_condition_deserializer(obj_dict):
660662

661663
def loads(conditions_string):
662664
""" Deserializes the conditions property into its corresponding
663-
components: the condition_structure and the condition_list.
665+
components: the condition_structure and the condition_list.
664666
665-
Args:
666-
conditions_string: String defining valid and/or conditions.
667+
Args:
668+
conditions_string: String defining valid and/or conditions.
667669
668-
Returns:
669-
A tuple of (condition_structure, condition_list).
670-
condition_structure: nested list of operators and placeholders for operands.
671-
condition_list: list of conditions whose index correspond to the values of the placeholders.
672-
"""
670+
Returns:
671+
A tuple of (condition_structure, condition_list).
672+
condition_structure: nested list of operators and placeholders for operands.
673+
condition_list: list of conditions whose index correspond to the values of the placeholders.
674+
"""
673675
decoder = ConditionDecoder(_audience_condition_deserializer)
674676

675677
# Create a custom JSONDecoder using the ConditionDecoder's object_hook method

0 commit comments

Comments
 (0)