@@ -526,6 +526,14 @@ def _pad_zeros(release, n):
526526 release = list (release ) + [0 ] * padding
527527 return tuple (release )
528528
529+ def _version_eqq (left , right ):
530+ if left .is_prefix or right .is_prefix :
531+ fail (_prefix_err (left , "<" , right ))
532+
533+ # https://peps.python.org/pep-0440/#arbitrary-equality
534+ # > simple string equality operations
535+ return left .norm == right .norm
536+
529537def _version_eq (left , right ):
530538 if left .is_prefix and right .is_prefix :
531539 fail ("Invalid comparison: both versions cannot be prefix matching" )
@@ -552,7 +560,21 @@ def _version_eq(left, right):
552560 ##and left.local == right.local
553561 )
554562
563+ def _version_ne (left , right ):
564+ return not _version_eq (left , right )
565+
566+ def _prefix_err (left , op , right ):
567+ if left .is_prefix or right .is_prefix :
568+ fail ("PEP440: only '==' and '!=' operators can use prefix matching: {} {} {}" .format (
569+ left ,
570+ op ,
571+ right ,
572+ ))
573+
555574def _version_lt (left , right ):
575+ if left .is_prefix or right .is_prefix :
576+ fail (_prefix_err (left , "<" , right ))
577+
556578 if left .epoch > right .epoch :
557579 return False
558580 elif left .epoch < right .epoch :
@@ -577,6 +599,9 @@ def _version_lt(left, right):
577599 return False
578600
579601def _version_gt (left , right ):
602+ if left .is_prefix or right .is_prefix :
603+ fail (_prefix_err (left , ">" , right ))
604+
580605 if left .epoch > right .epoch :
581606 return True
582607 elif left .epoch < right .epoch :
@@ -607,20 +632,29 @@ def _version_gt(left, right):
607632 return False
608633
609634def _version_ge (left , right ):
635+ if left .is_prefix or right .is_prefix :
636+ fail (_prefix_err (left , ">=" , right ))
637+
610638 # PEP440: simple order check
611639 # https://peps.python.org/pep-0440/#inclusive-ordered-comparison
612640 _left = left .key (local = False )
613641 _right = right .key (local = False )
614642 return _left > _right or _version_eq (left , right )
615643
616644def _version_le (left , right ):
645+ if left .is_prefix or right .is_prefix :
646+ fail (_prefix_err (left , "<=" , right ))
647+
617648 # PEP440: simple order check
618649 # https://peps.python.org/pep-0440/#inclusive-ordered-comparison
619650 _left = left .key (local = False )
620651 _right = right .key (local = False )
621652 return _left < _right or _version_eq (left , right )
622653
623654def _version_compatible (left , right ):
655+ if left .is_prefix or right .is_prefix :
656+ fail (_prefix_err (left , "~=" , right ))
657+
624658 # https://peps.python.org/pep-0440/#compatible-release
625659 # Note, the ~= operator can be also expressed as:
626660 # >= V.N, == V.*
@@ -717,11 +751,12 @@ def _new_version(*, epoch = 0, release, pre = "", post = "", dev = "", local = "
717751 is_prefix = is_prefix ,
718752 norm = norm ,
719753 eq = lambda x : _version_eq (self , x ), # buildifier: disable=uninitialized
720- ne = lambda x : not _version_eq (self , x ), # buildifier: disable=uninitialized
721- lt = lambda x : _version_lt (self , x ), # buildifier: disable=uninitialized
754+ eqq = lambda x : _version_eqq (self , x ), # buildifier: disable=uninitialized
755+ ge = lambda x : _version_ge (self , x ), # buildifier: disable=uninitialized
722756 gt = lambda x : _version_gt (self , x ), # buildifier: disable=uninitialized
723757 le = lambda x : _version_le (self , x ), # buildifier: disable=uninitialized
724- ge = lambda x : _version_ge (self , x ), # buildifier: disable=uninitialized
758+ lt = lambda x : _version_lt (self , x ), # buildifier: disable=uninitialized
759+ ne = lambda x : _version_ne (self , x ), # buildifier: disable=uninitialized
725760 compatible = lambda x : _version_compatible (self , x ), # buildifier: disable=uninitialized
726761 str = lambda : norm ,
727762 key = lambda * , local = True : _key (self , local = local ), # buildifier: disable=uninitialized
0 commit comments