Skip to content

Operators

Matches = Binary[Version, Version, bool] module-attribute

The (version, against) -> bool function.

PartialMatches = Unary[Version, bool] module-attribute

The (version) -> bool function.

Translate = Unary[Version, VersionSet] module-attribute

The (version) -> version_set function.

OperatorType

Bases: Enum

Represents operator types.

Source code in versions/operators.py
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
class OperatorType(Enum):
    """Represents operator types."""

    # official constraints
    TILDE_EQUAL = TILDE_EQUAL
    """The binary `~=` operator."""
    DOUBLE_EQUAL = DOUBLE_EQUAL
    """The binary `==` operator."""
    NOT_EQUAL = NOT_EQUAL
    """The binary `!=` operator."""
    LESS = LESS
    """The binary `<` operator."""
    LESS_OR_EQUAL = LESS_OR_EQUAL
    """The binary `<=` operator."""
    GREATER = GREATER
    """The binary `>` operator."""
    GREATER_OR_EQUAL = GREATER_OR_EQUAL
    """The binary `>=` operator."""
    # additional constraints
    CARET = CARET
    """The unary `^` operator."""
    EQUAL = EQUAL
    """The binary `=` operator."""
    TILDE = TILDE
    """The unary `~` operator."""
    # wildcard constraints
    WILDCARD_DOUBLE_EQUAL = WILDCARD_DOUBLE_EQUAL
    """The wildcard binary `==*` operator."""
    WILDCARD_EQUAL = WILDCARD_EQUAL
    """The wildcard binary `=*` operator."""
    WILDCARD_NOT_EQUAL = WILDCARD_NOT_EQUAL
    """The wildcard binary `!=*` operator."""

    def is_tilde_equal(self) -> bool:
        return self is type(self).TILDE_EQUAL

    def is_double_equal(self) -> bool:
        return self is type(self).DOUBLE_EQUAL

    def is_not_equal(self) -> bool:
        return self is type(self).NOT_EQUAL

    def is_less(self) -> bool:
        return self is type(self).LESS

    def is_less_or_equal(self) -> bool:
        return self is type(self).LESS_OR_EQUAL

    def is_greater(self) -> bool:
        return self is type(self).GREATER

    def is_greater_or_equal(self) -> bool:
        return self is type(self).GREATER_OR_EQUAL

    def is_caret(self) -> bool:
        return self is type(self).CARET

    def is_equal(self) -> bool:
        return self is type(self).EQUAL

    def is_tilde(self) -> bool:
        return self is type(self).TILDE

    def is_wildcard_double_equal(self) -> bool:
        return self is type(self).WILDCARD_DOUBLE_EQUAL

    def is_wildcard_equal(self) -> bool:
        return self is type(self).WILDCARD_EQUAL

    def is_wildcard_not_equal(self) -> bool:
        return self is type(self).WILDCARD_NOT_EQUAL

    def is_wildcard(self) -> bool:
        """Checks if an operator is *wildcard*.

        Returns:
            Whether the operator is *wildcard*.
        """
        return self in WILDCARD

    def in_equals(self) -> bool:
        return self in EQUALS

    def in_wildcard_equals(self) -> bool:
        return self in WILDCARD_EQUALS

    def is_unary(self) -> bool:
        """Checks if an operator is *unary*.

        Returns:
            Whether the operator is *unary*.
        """
        return self in UNARY

    def __eq__(self, other: Any) -> bool:
        if is_same_type(other, self):
            return (
                (self.in_equals() and other.in_equals())
                or (self.in_wildcard_equals() and other.in_wildcard_equals())
                or super().__eq__(other)
            )

        return NotImplemented  # pragma: no cover  # not tested

    def __hash__(self) -> int:
        return super().__hash__()

    @property
    def string(self) -> str:
        return wildcard_type(self.value)

TILDE_EQUAL = TILDE_EQUAL class-attribute instance-attribute

The binary ~= operator.

DOUBLE_EQUAL = DOUBLE_EQUAL class-attribute instance-attribute

The binary == operator.

NOT_EQUAL = NOT_EQUAL class-attribute instance-attribute

The binary != operator.

LESS = LESS class-attribute instance-attribute

The binary < operator.

LESS_OR_EQUAL = LESS_OR_EQUAL class-attribute instance-attribute

The binary <= operator.

GREATER = GREATER class-attribute instance-attribute

The binary > operator.

GREATER_OR_EQUAL = GREATER_OR_EQUAL class-attribute instance-attribute

The binary >= operator.

CARET = CARET class-attribute instance-attribute

The unary ^ operator.

EQUAL = EQUAL class-attribute instance-attribute

The binary = operator.

TILDE = TILDE class-attribute instance-attribute

The unary ~ operator.

WILDCARD_DOUBLE_EQUAL = WILDCARD_DOUBLE_EQUAL class-attribute instance-attribute

The wildcard binary ==* operator.

WILDCARD_EQUAL = WILDCARD_EQUAL class-attribute instance-attribute

The wildcard binary =* operator.

WILDCARD_NOT_EQUAL = WILDCARD_NOT_EQUAL class-attribute instance-attribute

The wildcard binary !=* operator.

is_wildcard() -> bool

Checks if an operator is wildcard.

Returns:

Type Description
bool

Whether the operator is wildcard.

Source code in versions/operators.py
736
737
738
739
740
741
742
def is_wildcard(self) -> bool:
    """Checks if an operator is *wildcard*.

    Returns:
        Whether the operator is *wildcard*.
    """
    return self in WILDCARD

is_unary() -> bool

Checks if an operator is unary.

Returns:

Type Description
bool

Whether the operator is unary.

Source code in versions/operators.py
750
751
752
753
754
755
756
def is_unary(self) -> bool:
    """Checks if an operator is *unary*.

    Returns:
        Whether the operator is *unary*.
    """
    return self in UNARY

Operator

Bases: Representation, ToString

Represents operators.

Source code in versions/operators.py
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
@frozen(repr=False)
class Operator(Representation, ToString):
    """Represents operators."""

    type: OperatorType
    """The operator type."""

    version: Version
    """The operator version."""

    def validate(self) -> None:
        if self.type.is_tilde_equal():
            if not self.version.last_index:
                raise ValueError(CAN_NOT_USE_TILDE_EQUAL)

    __attrs_post_init__ = validate

    def is_tilde_equal(self) -> bool:
        return self.type.is_tilde_equal()

    def is_double_equal(self) -> bool:
        return self.type.is_double_equal()

    def is_not_equal(self) -> bool:
        return self.type.is_not_equal()

    def is_less(self) -> bool:
        return self.type.is_less()

    def is_less_or_equal(self) -> bool:
        return self.type.is_less_or_equal()

    def is_greater(self) -> bool:
        return self.type.is_greater()

    def is_greater_or_equal(self) -> bool:
        return self.type.is_greater_or_equal()

    def is_caret(self) -> bool:
        return self.type.is_caret()

    def is_equal(self) -> bool:
        return self.type.is_equal()

    def is_tilde(self) -> bool:
        return self.type.is_tilde()

    def is_wildcard_double_equal(self) -> bool:
        return self.type.is_wildcard_double_equal()

    def is_wildcard_equal(self) -> bool:
        return self.type.is_wildcard_equal()

    def is_wildcard_not_equal(self) -> bool:
        return self.type.is_wildcard_not_equal()

    def is_unary(self) -> bool:
        """Checks if an operator is *unary*.

        Returns:
            Whether the operator is *unary*.
        """
        return self.type.is_unary()

    def is_wildcard(self) -> bool:
        """Checks if an operator is *wildcard*.

        Returns:
            Whether the operator is *wildcard*.
        """
        return self.type.is_wildcard()

    @classmethod
    def tilde_equal(cls, version: Version) -> Self:
        return cls(OperatorType.TILDE_EQUAL, version)

    @classmethod
    def double_equal(cls, version: Version) -> Self:
        return cls(OperatorType.DOUBLE_EQUAL, version)

    @classmethod
    def not_equal(cls, version: Version) -> Self:
        return cls(OperatorType.NOT_EQUAL, version)

    @classmethod
    def less(cls, version: Version) -> Self:
        return cls(OperatorType.LESS, version)

    @classmethod
    def less_or_equal(cls, version: Version) -> Self:
        return cls(OperatorType.LESS_OR_EQUAL, version)

    @classmethod
    def greater(cls, version: Version) -> Self:
        return cls(OperatorType.GREATER, version)

    @classmethod
    def greater_or_equal(cls, version: Version) -> Self:
        return cls(OperatorType.GREATER_OR_EQUAL, version)

    @classmethod
    def caret(cls, version: Version) -> Self:
        return cls(OperatorType.CARET, version)

    @classmethod
    def equal(cls, version: Version) -> Self:
        return cls(OperatorType.EQUAL, version)

    @classmethod
    def tilde(cls, version: Version) -> Self:
        return cls(OperatorType.TILDE, version)

    @classmethod
    def wildcard_double_equal(cls, version: Version) -> Self:
        return cls(OperatorType.WILDCARD_DOUBLE_EQUAL, version)

    @classmethod
    def wildcard_equal(cls, version: Version) -> Self:
        return cls(OperatorType.WILDCARD_EQUAL, version)

    @classmethod
    def wildcard_not_equal(cls, version: Version) -> Self:
        return cls(OperatorType.WILDCARD_NOT_EQUAL, version)

    @property
    def matches_and_translate(self) -> Tuple[Matches, Translate]:
        return OPERATOR[self.type]

    @property
    def matches(self) -> Matches:
        """The `matches` function representing the operator."""
        matches, _translate = self.matches_and_translate

        return matches

    @property
    def translate(self) -> Translate:
        """The `translate` function representing the operator."""
        _matches, translate = self.matches_and_translate

        return translate

    @property
    def partial_matches(self) -> PartialMatches:
        """The partial `matches` function with
        [`self.version`][versions.operators.Operator.version] as the `against` version.
        """
        return partial_matches(self.matches, self.version)

    def to_string(self) -> str:
        """Converts an [`Operator`][versions.operators.Operator] to its string representation.

        Returns:
            The operator string.
        """
        string = self.version.to_string()

        if self.is_wildcard():
            string = wildcard_string(string)

        if self.is_unary():
            return concat_empty_args(self.type.string, string)

        return concat_space_args(self.type.string, string)

    def to_short_string(self) -> str:
        """Converts an [`Operator`][versions.operators.Operator]
        to its *short* string representation.

        Returns:
            The *short* operator string.
        """
        string = self.version.to_short_string()

        if self.is_wildcard():
            string = wildcard_string(string)

        return concat_empty_args(self.type.string, string)

type: OperatorType instance-attribute

The operator type.

version: Version instance-attribute

The operator version.

matches: Matches property

The matches function representing the operator.

translate: Translate property

The translate function representing the operator.

partial_matches: PartialMatches property

The partial matches function with self.version as the against version.

is_unary() -> bool

Checks if an operator is unary.

Returns:

Type Description
bool

Whether the operator is unary.

Source code in versions/operators.py
861
862
863
864
865
866
867
def is_unary(self) -> bool:
    """Checks if an operator is *unary*.

    Returns:
        Whether the operator is *unary*.
    """
    return self.type.is_unary()

is_wildcard() -> bool

Checks if an operator is wildcard.

Returns:

Type Description
bool

Whether the operator is wildcard.

Source code in versions/operators.py
869
870
871
872
873
874
875
def is_wildcard(self) -> bool:
    """Checks if an operator is *wildcard*.

    Returns:
        Whether the operator is *wildcard*.
    """
    return self.type.is_wildcard()

to_string() -> str

Converts an Operator to its string representation.

Returns:

Type Description
str

The operator string.

Source code in versions/operators.py
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
def to_string(self) -> str:
    """Converts an [`Operator`][versions.operators.Operator] to its string representation.

    Returns:
        The operator string.
    """
    string = self.version.to_string()

    if self.is_wildcard():
        string = wildcard_string(string)

    if self.is_unary():
        return concat_empty_args(self.type.string, string)

    return concat_space_args(self.type.string, string)

to_short_string() -> str

Converts an Operator to its short string representation.

Returns:

Type Description
str

The short operator string.

Source code in versions/operators.py
970
971
972
973
974
975
976
977
978
979
980
981
982
def to_short_string(self) -> str:
    """Converts an [`Operator`][versions.operators.Operator]
    to its *short* string representation.

    Returns:
        The *short* operator string.
    """
    string = self.version.to_short_string()

    if self.is_wildcard():
        string = wildcard_string(string)

    return concat_empty_args(self.type.string, string)

next_caret_breaking(version: V) -> V

Returns the next breaking version according to the caret (^) strategy.

This function is slightly convoluted due to handling 0.x.y and 0.0.z versions.

See next_breaking for more information.

Example
>>> from versions import next_caret_breaking, parse_version
>>> version = parse_version("1.0.0")
>>> version
<Version (1.0.0)>
>>> next_caret_breaking(version)
<Version (2.0.0)>

Parameters:

Name Type Description Default
version V

The version to find next breaking version of.

required

Returns:

Type Description
V

The next breaking version according to the version.

Source code in versions/operators.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def next_caret_breaking(version: V) -> V:
    """Returns the next breaking version according to the *caret* (`^`) strategy.

    This function is slightly convoluted due to handling `0.x.y` and `0.0.z` versions.

    See [`next_breaking`][versions.version.Version.next_breaking] for more information.

    Example:
        ```python
        >>> from versions import next_caret_breaking, parse_version
        >>> version = parse_version("1.0.0")
        >>> version
        <Version (1.0.0)>
        >>> next_caret_breaking(version)
        <Version (2.0.0)>
        ```

    Arguments:
        version: The version to find next breaking version of.

    Returns:
        The next breaking version according to the `version`.
    """
    return version.next_breaking()

next_tilde_equal_breaking(version: V) -> V

Returns the next breaking version according to the tilde-equal (~=) strategy.

This function simply bumps the second to last part of the release.

Example
>>> from versions import next_tilde_equal_breaking, parse_version
>>> version = parse_version("1.2.0")
>>> version
<Version (1.2.0)>
>>> next_tilde_equal_breaking(version)
<Version (1.3.0)>
>>> invalid = parse_version("1")
>>> next_tilde_equal_breaking(invalid)
Traceback (most recent call last):
  ...
ValueError: `~=` can not be used with with a single version segment

Parameters:

Name Type Description Default
version V

The version to find the next breaking version of.

required

Returns:

Type Description
V

The next breaking Version according to the version.

Source code in versions/operators.py
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
def next_tilde_equal_breaking(version: V) -> V:
    """Returns the next breaking version according to the *tilde-equal* (`~=`) strategy.

    This function simply bumps the second to last part of the release.

    Example:
        ```python
        >>> from versions import next_tilde_equal_breaking, parse_version
        >>> version = parse_version("1.2.0")
        >>> version
        <Version (1.2.0)>
        >>> next_tilde_equal_breaking(version)
        <Version (1.3.0)>
        ```

        ```python
        >>> invalid = parse_version("1")
        >>> next_tilde_equal_breaking(invalid)
        Traceback (most recent call last):
          ...
        ValueError: `~=` can not be used with with a single version segment
        ```

    Arguments:
        version: The version to find the next breaking version of.

    Returns:
        The next breaking [`Version`][versions.version.Version] according to the `version`.
    """
    index = version.last_index

    if index:
        return version.to_stable().next_at(index - 1)

    raise ValueError(CAN_NOT_USE_TILDE_EQUAL)

next_tilde_breaking(version: V) -> V

Returns the next breaking version according to the tilde (~) strategy.

This function simply bumps the minor part of the release if it is present, otherwise the major part is bumped.

Example
>>> from versions import next_tilde_equal_breaking, parse_version
>>> version = parse_version("2.1.0")
>>> version
<Version (2.1.0)>
>>> next_tilde_breaking(version)
<Version (2.2.0)>

Parameters:

Name Type Description Default
version V

The version to find the next breaking version of.

required

Returns:

Type Description
V

The next breaking Version according to the version.

Source code in versions/operators.py
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
def next_tilde_breaking(version: V) -> V:
    """Returns the next breaking version according to the *tilde* (`~`) strategy.

    This function simply bumps the minor part of the release
    if it is present, otherwise the major part is bumped.

    Example:
        ```python
        >>> from versions import next_tilde_equal_breaking, parse_version
        >>> version = parse_version("2.1.0")
        >>> version
        <Version (2.1.0)>
        >>> next_tilde_breaking(version)
        <Version (2.2.0)>
        ```

    Arguments:
        version: The version to find the next breaking version of.

    Returns:
        The next breaking [`Version`][versions.version.Version] according to the `version`.
    """
    if version.has_minor():
        return version.next_minor()

    return version.next_major()

next_wildcard_breaking(version: V) -> Optional[V]

Returns the next breaking version according to the wildcard (*) strategy.

There are three cases to handle:

  • If the wildcard is used within the pre-release tag of the version, next breaking version has the same release with pre-release tag removed. For example, x.y.z-rc.* is bumped to x.y.z.

  • If the wildcard is used within the post-release tag of the version, next breaking version has the last part of the release bumped. For instance, x.y.z-post.* is bumped to x.y.z', where z' = z + 1.

  • Otherwise, the second to last part of the release is bumped. For example, x.y.* is bumped to x.y'.0, where y' = y + 1.

Note

This function returns None if the given version is *.

Example
>>> from versions import next_wildcard_breaking, parse_version
>>> version = parse_version("4.2.0")
>>> version
<Version (4.2.0)>
>>> next_wildcard_breaking(version)
<Version (4.3.0)>
>>> other = parse_version("1.2.3-rc.0")
>>> other
<Version (1.2.3-rc.0)>
>>> next_wildcard_breaking(other)
<Version (1.2.3)>
>>> another = parse_version("0.6.8-post.0")
>>> another
<Version (0.6.8-post.0)>
>>> next_wildcard_breaking(another)
<Version (0.6.9)>  # nice

Parameters:

Name Type Description Default
version V

The version to find the next breaking version of.

required

Returns:

Type Description
Optional[V]

The next breaking Version according to the version, or None.

Source code in versions/operators.py
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
def next_wildcard_breaking(version: V) -> Optional[V]:
    """Returns the next breaking version according to the *wildcard* (`*`) strategy.

    There are three cases to handle:

    - If the wildcard is used within the *pre-release* tag of the version,
      next breaking version has the same release with *pre-release* tag removed.
      For example, `x.y.z-rc.*` is bumped to `x.y.z`.

    - If the wildcard is used within the *post-release* tag of the version,
      next breaking version has the last part of the release bumped.
      For instance, `x.y.z-post.*` is bumped to `x.y.z'`, where `z' = z + 1`.

    - Otherwise, the second to last part of the release is bumped.
      For example, `x.y.*` is bumped to `x.y'.0`, where `y' = y + 1`.

    Note:
        This function returns [`None`][None] if the given version is `*`.

    Example:
        ```python
        >>> from versions import next_wildcard_breaking, parse_version
        >>> version = parse_version("4.2.0")
        >>> version
        <Version (4.2.0)>
        >>> next_wildcard_breaking(version)
        <Version (4.3.0)>
        >>> other = parse_version("1.2.3-rc.0")
        >>> other
        <Version (1.2.3-rc.0)>
        >>> next_wildcard_breaking(other)
        <Version (1.2.3)>
        >>> another = parse_version("0.6.8-post.0")
        >>> another
        <Version (0.6.8-post.0)>
        >>> next_wildcard_breaking(another)
        <Version (0.6.9)>  # nice
        ```

    Arguments:
        version: The version to find the next breaking version of.

    Returns:
        The next breaking [`Version`][versions.version.Version] according
            to the `version`, or [`None`][None].
    """
    index = version.last_index

    if version.is_stable() and not version.is_post_release():
        # the wildcard was used within the release segment

        if not index:
            return None

        index -= 1

    return version.next_at(index)  # this will take care of unstable releases

matches_caret(version: Version, against: Version) -> bool

Checks if the version matches the caret (^) specification.

This is equivalent to:

against <= version < next_caret_breaking(against)

Parameters:

Name Type Description Default
version Version

The version to check.

required
against Version

The version to check the version against.

required

Returns:

Type Description
bool

Whether the version matches against.

Source code in versions/operators.py
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
def matches_caret(version: Version, against: Version) -> bool:
    """Checks if the `version` matches the *caret* (`^`) specification.

    This is equivalent to:

    ```python
    against <= version < next_caret_breaking(against)
    ```

    Arguments:
        version: The version to check.
        against: The version to check the `version` against.

    Returns:
        Whether the `version` matches `against`.
    """
    return against <= version < next_caret_breaking(against)

matches_tilde_equal(version: Version, against: Version) -> bool

Checks if the version matches the tilde-equal (~=) specification.

This is equivalent to:

against <= version < next_tilde_equal_breaking(against)

Parameters:

Name Type Description Default
version Version

The version to check.

required
against Version

The version to check the version against.

required

Returns:

Type Description
bool

Whether the version matches against.

Source code in versions/operators.py
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
def matches_tilde_equal(version: Version, against: Version) -> bool:
    """Checks if the `version` matches the *tilde-equal* (`~=`) specification.

    This is equivalent to:

    ```python
    against <= version < next_tilde_equal_breaking(against)
    ```

    Arguments:
        version: The version to check.
        against: The version to check the `version` against.

    Returns:
        Whether the `version` matches `against`.
    """
    return against <= version < next_tilde_equal_breaking(against)

matches_tilde(version: Version, against: Version) -> bool

Checks if the version matches the tilde (~) specification.

This is equivalent to:

against <= version < next_tilde_breaking(against)

Parameters:

Name Type Description Default
version Version

The version to check.

required
against Version

The version to check the version against.

required

Returns:

Type Description
bool

Whether the version matches against.

Source code in versions/operators.py
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
def matches_tilde(version: Version, against: Version) -> bool:
    """Checks if the `version` matches the *tilde* (`~`) specification.

    This is equivalent to:

    ```python
    against <= version < next_tilde_breaking(against)
    ```

    Arguments:
        version: The version to check.
        against: The version to check the `version` against.

    Returns:
        Whether the `version` matches `against`.
    """
    return against <= version < next_tilde_breaking(against)

matches_equal(version: Version, against: Version) -> bool

Checks if the version matches the equal (=) specification.

This is equivalent to:

version == against

Parameters:

Name Type Description Default
version Version

The version to check.

required
against Version

The version to check the version against.

required

Returns:

Type Description
bool

Whether the version matches against.

Source code in versions/operators.py
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
def matches_equal(version: Version, against: Version) -> bool:
    """Checks if the `version` matches the *equal* (`=`) specification.

    This is equivalent to:

    ```python
    version == against
    ```

    Arguments:
        version: The version to check.
        against: The version to check the `version` against.

    Returns:
        Whether the `version` matches `against`.
    """
    return version == against

matches_not_equal(version: Version, against: Version) -> bool

Checks if the version matches the not-equal (!=) specification.

This is equivalent to:

version != against

Parameters:

Name Type Description Default
version Version

The version to check.

required
against Version

The version to check the version against.

required

Returns:

Type Description
bool

Whether the version matches against.

Source code in versions/operators.py
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
def matches_not_equal(version: Version, against: Version) -> bool:
    """Checks if the `version` matches the *not-equal* (`!=`) specification.

    This is equivalent to:

    ```python
    version != against
    ```

    Arguments:
        version: The version to check.
        against: The version to check the `version` against.

    Returns:
        Whether the `version` matches `against`.
    """
    return version != against

matches_less(version: Version, against: Version) -> bool

Checks if the version matches the less (<) specification.

This is equivalent to:

version < against

Parameters:

Name Type Description Default
version Version

The version to check.

required
against Version

The version to check the version against.

required

Returns:

Type Description
bool

Whether the version matches against.

Source code in versions/operators.py
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
def matches_less(version: Version, against: Version) -> bool:
    """Checks if the `version` matches the *less* (`<`) specification.

    This is equivalent to:

    ```python
    version < against
    ```

    Arguments:
        version: The version to check.
        against: The version to check the `version` against.

    Returns:
        Whether the `version` matches `against`.
    """

    return version < against

matches_less_or_equal(version: Version, against: Version) -> bool

Checks if the version matches the less-or-equal (<=) specification.

This is equivalent to:

version <= against

Parameters:

Name Type Description Default
version Version

The version to check.

required
against Version

The version to check the version against.

required

Returns:

Type Description
bool

Whether the version matches against.

Source code in versions/operators.py
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
def matches_less_or_equal(version: Version, against: Version) -> bool:
    """Checks if the `version` matches the *less-or-equal* (`<=`) specification.

    This is equivalent to:

    ```python
    version <= against
    ```

    Arguments:
        version: The version to check.
        against: The version to check the `version` against.

    Returns:
        Whether the `version` matches `against`.
    """
    return version <= against

matches_greater(version: Version, against: Version) -> bool

Checks if the version matches the greater (>) specification.

This is equivalent to:

version > against

Parameters:

Name Type Description Default
version Version

The version to check.

required
against Version

The version to check the version against.

required

Returns:

Type Description
bool

Whether the version matches against.

Source code in versions/operators.py
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
def matches_greater(version: Version, against: Version) -> bool:
    """Checks if the `version` matches the *greater* (`>`) specification.

    This is equivalent to:

    ```python
    version > against
    ```

    Arguments:
        version: The version to check.
        against: The version to check the `version` against.

    Returns:
        Whether the `version` matches `against`.
    """
    return version > against

matches_greater_or_equal(version: Version, against: Version) -> bool

Checks if the version matches the greater-or-equal (>=) specification.

This is equivalent to:

version >= against

Parameters:

Name Type Description Default
version Version

The version to check.

required
against Version

The version to check the version against.

required

Returns:

Type Description
bool

Whether the version matches against.

Source code in versions/operators.py
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
def matches_greater_or_equal(version: Version, against: Version) -> bool:
    """Checks if the `version` matches the *greater-or-equal* (`>=`) specification.

    This is equivalent to:

    ```python
    version >= against
    ```

    Arguments:
        version: The version to check.
        against: The version to check the `version` against.

    Returns:
        Whether the `version` matches `against`.
    """
    return version >= against

matches_wildcard_equal(version: Version, against: Version) -> bool

Checks if the version matches the wildcard-equal (=*) specification.

This is equivalent to:

wildcard = next_wildcard_breaking(against)

wildcard is None or against <= version < wildcard

Parameters:

Name Type Description Default
version Version

The version to check.

required
against Version

The version to check the version against.

required

Returns:

Type Description
bool

Whether the version matches against.

Source code in versions/operators.py
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
def matches_wildcard_equal(version: Version, against: Version) -> bool:
    """Checks if the `version` matches the *wildcard-equal* (`=*`) specification.

    This is equivalent to:

    ```python
    wildcard = next_wildcard_breaking(against)

    wildcard is None or against <= version < wildcard
    ```

    Arguments:
        version: The version to check.
        against: The version to check the `version` against.

    Returns:
        Whether the `version` matches `against`.
    """
    wildcard = next_wildcard_breaking(against)

    if wildcard is None:
        return True

    return against <= version < wildcard

matches_wildcard_not_equal(version: Version, against: Version) -> bool

Checks if the version matches the wildcard-not-equal (!=*) specification.

This is equivalent to:

wildcard = next_wildcard_breaking(against)

wildcard is not None and (version < against or version >= wildcard)

Parameters:

Name Type Description Default
version Version

The version to check.

required
against Version

The version to check the version against.

required

Returns:

Type Description
bool

Whether the version matches against.

Source code in versions/operators.py
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
def matches_wildcard_not_equal(version: Version, against: Version) -> bool:
    """Checks if the `version` matches the *wildcard-not-equal* (`!=*`) specification.

    This is equivalent to:

    ```python
    wildcard = next_wildcard_breaking(against)

    wildcard is not None and (version < against or version >= wildcard)
    ```

    Arguments:
        version: The version to check.
        against: The version to check the `version` against.

    Returns:
        Whether the `version` matches `against`.
    """
    return not matches_wildcard_equal(version, against)

translate_caret(version: Version) -> VersionRange

Translates the version into a version set according to the caret (^) strategy.

This function returns the [version, next_caret_breaking(version)) range.

Parameters:

Name Type Description Default
version Version

The version to translate.

required

Returns:

Type Description
VersionRange

The version set representing the caret specification.

Source code in versions/operators.py
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
def translate_caret(version: Version) -> VersionRange:
    """Translates the `version` into a version set according to the *caret* (`^`) strategy.

    This function returns the `[version, next_caret_breaking(version))` range.

    Arguments:
        version: The version to translate.

    Returns:
        The version set representing the *caret* specification.
    """
    return VersionRange(
        min=version,
        max=next_caret_breaking(version),
        include_min=True,
        include_max=False,
    )

translate_tilde_equal(version: Version) -> VersionRange

Translates the version into a version set according to the tilde-equal (~=) strategy.

This function returns the [version, next_tilde_equal_breaking(version)) range.

Parameters:

Name Type Description Default
version Version

The version to translate.

required

Returns:

Type Description
VersionRange

The version set representing the tilde-equal specification.

Source code in versions/operators.py
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
def translate_tilde_equal(version: Version) -> VersionRange:
    """Translates the `version` into a version set according to the *tilde-equal* (`~=`) strategy.

    This function returns the `[version, next_tilde_equal_breaking(version))` range.

    Arguments:
        version: The version to translate.

    Returns:
        The version set representing the *tilde-equal* specification.
    """
    return VersionRange(
        min=version,
        max=next_tilde_equal_breaking(version),
        include_min=True,
        include_max=False,
    )

translate_tilde(version: Version) -> VersionRange

Translates the version into a version set according to the tilde (~) strategy.

This function returns the [version, next_tilde_breaking(version)) range.

Parameters:

Name Type Description Default
version Version

The version to translate.

required

Returns:

Type Description
VersionRange

The version set representing the tilde-equal specification.

Source code in versions/operators.py
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
def translate_tilde(version: Version) -> VersionRange:
    """Translates the `version` into a version set according to the *tilde* (`~`) strategy.

    This function returns the `[version, next_tilde_breaking(version))` range.

    Arguments:
        version: The version to translate.

    Returns:
        The version set representing the *tilde-equal* specification.
    """
    return VersionRange(
        min=version,
        max=next_tilde_breaking(version),
        include_min=True,
        include_max=False,
    )

translate_equal(version: Version) -> VersionPoint

Translates the version into a version set according to the equal (=) strategy.

This function returns the [version, version] range (aka single version, {version}).

Parameters:

Name Type Description Default
version Version

The version to translate.

required

Returns:

Type Description
VersionPoint

The version set representing the equal specification.

Source code in versions/operators.py
526
527
528
529
530
531
532
533
534
535
536
537
def translate_equal(version: Version) -> VersionPoint:
    """Translates the `version` into a version set according to the *equal* (`=`) strategy.

    This function returns the `[version, version]` range (aka single `version`, `{version}`).

    Arguments:
        version: The version to translate.

    Returns:
        The version set representing the *equal* specification.
    """
    return VersionPoint(version)

translate_not_equal(version: Version) -> VersionUnion

Translates the version into a version set according to the not-equal (!=) strategy.

This function returns the (ε, version) | (version, ω) union.

Parameters:

Name Type Description Default
version Version

The version to translate.

required

Returns:

Type Description
VersionUnion

The version set representing the not-equal specification.

Source code in versions/operators.py
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
def translate_not_equal(version: Version) -> VersionUnion:
    """Translates the `version` into a version set according to the *not-equal* (`!=`) strategy.

    This function returns the `(ε, version) | (version, ω)` union.

    Arguments:
        version: The version to translate.

    Returns:
        The version set representing the *not-equal* specification.
    """
    result = translate_equal(version).complement()

    if is_version_union(result):
        return result

    raise InternalError(UNEXPECTED_EQUAL_COMPLEMENT)

translate_less(version: Version) -> VersionRange

Translates the version into a version set according to the less (<) strategy.

This function returns the (ε, version) range.

Parameters:

Name Type Description Default
version Version

The version to translate.

required

Returns:

Type Description
VersionRange

The version set representing the less specification.

Source code in versions/operators.py
562
563
564
565
566
567
568
569
570
571
572
573
def translate_less(version: Version) -> VersionRange:
    """Translates the `version` into a version set according to the *less* (`<`) strategy.

    This function returns the `(ε, version)` range.

    Arguments:
        version: The version to translate.

    Returns:
        The version set representing the *less* specification.
    """
    return VersionRange(max=version, include_max=False)

translate_less_or_equal(version: Version) -> VersionRange

Translates the version into a version set according to the less-or-equal (<=) strategy.

This function returns the (ε, version] range.

Parameters:

Name Type Description Default
version Version

The version to translate.

required

Returns:

Type Description
VersionRange

The version set representing the less-or-equal specification.

Source code in versions/operators.py
576
577
578
579
580
581
582
583
584
585
586
587
def translate_less_or_equal(version: Version) -> VersionRange:
    """Translates the `version` into a version set according to the *less-or-equal* (`<=`) strategy.

    This function returns the `(ε, version]` range.

    Arguments:
        version: The version to translate.

    Returns:
        The version set representing the *less-or-equal* specification.
    """
    return VersionRange(max=version, include_max=True)

translate_greater(version: Version) -> VersionRange

Translates the version into a version set according to the greater (>) strategy.

This function returns the (version, ω) range.

Parameters:

Name Type Description Default
version Version

The version to translate.

required

Returns:

Type Description
VersionRange

The version set representing the greater specification.

Source code in versions/operators.py
590
591
592
593
594
595
596
597
598
599
600
601
def translate_greater(version: Version) -> VersionRange:
    """Translates the `version` into a version set according to the *greater* (`>`) strategy.

    This function returns the `(version, ω)` range.

    Arguments:
        version: The version to translate.

    Returns:
        The version set representing the *greater* specification.
    """
    return VersionRange(min=version, include_min=False)

translate_greater_or_equal(version: Version) -> VersionRange

Translates the version into a version set according to the greater-or-equal (>=) strategy.

This function returns the [version, ω) range.

Parameters:

Name Type Description Default
version Version

The version to translate.

required

Returns:

Type Description
VersionRange

The version set representing the greater-or-equal specification.

Source code in versions/operators.py
604
605
606
607
608
609
610
611
612
613
614
615
616
def translate_greater_or_equal(version: Version) -> VersionRange:
    """Translates the `version` into a version set according to
    the *greater-or-equal* (`>=`) strategy.

    This function returns the `[version, ω)` range.

    Arguments:
        version: The version to translate.

    Returns:
        The version set representing the *greater-or-equal* specification.
    """
    return VersionRange(min=version, include_min=True)

translate_wildcard_equal(version: Version) -> VersionRange

Translates the version into a version set according to the wildcard-equal (==*) strategy.

This function returns the [version, next_wildcard_version(version)) range in most cases, except for when the version is *; then the (ε, ω) range is returned.

Parameters:

Name Type Description Default
version Version

The version to translate.

required

Returns:

Type Description
VersionRange

The version set representing the wildcard-equal specification.

Source code in versions/operators.py
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
def translate_wildcard_equal(version: Version) -> VersionRange:
    """Translates the `version` into a version set according to
    the *wildcard-equal* (`==*`) strategy.

    This function returns the `[version, next_wildcard_version(version))` range in most cases,
    except for when the version is `*`; then the `(ε, ω)` range is returned.

    Arguments:
        version: The version to translate.

    Returns:
        The version set representing the *wildcard-equal* specification.
    """
    wildcard = next_wildcard_breaking(version)

    if wildcard is None:
        return VersionRange()

    return VersionRange(min=version, max=wildcard, include_min=True, include_max=False)

translate_wildcard_not_equal(version: Version) -> Union[VersionEmpty, VersionUnion]

Translates the version into a version set according to the wildcard-not-equal (!=*) strategy.

This function returns the (ε, version) | (next_wildcard_breaking(version), ω) union in most cases, except for when the version is *; then the 0 empty set is returned.

Parameters:

Name Type Description Default
version Version

The version to translate.

required

Returns:

Type Description
Union[VersionEmpty, VersionUnion]

The version set representing the wildcard-not-equal specification.

Source code in versions/operators.py
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
def translate_wildcard_not_equal(version: Version) -> Union[VersionEmpty, VersionUnion]:
    """Translates the `version` into a version set according to
    the *wildcard-not-equal* (`!=*`) strategy.

    This function returns the `(ε, version) | (next_wildcard_breaking(version), ω)` union
    in most cases, except for when the version is `*`; then the `0` empty set is returned.

    Arguments:
        version: The version to translate.

    Returns:
        The version set representing the *wildcard-not-equal* specification.
    """
    result = translate_wildcard_equal(version).complement()

    if is_version_empty(result) or is_version_union(result):
        return result

    raise InternalError(UNEXPECTED_WILDCARD_EQUAL_COMPLEMENT)