Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
52141aae
Commit
52141aae
authored
Jan 27, 2009
by
Mark Dickinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #1717: Remove cmp. Stage 1: remove all uses of cmp and __cmp__ from
the standard library and tests.
parent
da4be9fd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
27 deletions
+36
-27
version.py
version.py
+36
-27
No files found.
version.py
View file @
52141aae
...
...
@@ -21,7 +21,7 @@ Every version number class implements the following interface:
an equivalent string -- ie. one that will generate an equivalent
version number instance)
* __repr__ generates Python code to recreate the version number instance
* _
_cmp__
compares the current instance with either another instance
* _
cmp
compares the current instance with either another instance
of the same class or a string (which will be parsed to an instance
of the same class, thus must follow the same rules)
"""
...
...
@@ -32,7 +32,7 @@ class Version:
"""Abstract base class for version numbering classes. Just provides
constructor (__init__) and reproducer (__repr__), because those
seem to be the same for all version numbering classes; and route
rich comparisons to _
_cmp__
.
rich comparisons to _
cmp
.
"""
def
__init__
(
self
,
vstring
=
None
):
...
...
@@ -43,37 +43,37 @@ class Version:
return
"%s ('%s')"
%
(
self
.
__class__
.
__name__
,
str
(
self
))
def
__eq__
(
self
,
other
):
c
=
self
.
_
_cmp__
(
other
)
c
=
self
.
_
cmp
(
other
)
if
c
is
NotImplemented
:
return
c
return
c
==
0
def
__ne__
(
self
,
other
):
c
=
self
.
_
_cmp__
(
other
)
c
=
self
.
_
cmp
(
other
)
if
c
is
NotImplemented
:
return
c
return
c
!=
0
def
__lt__
(
self
,
other
):
c
=
self
.
_
_cmp__
(
other
)
c
=
self
.
_
cmp
(
other
)
if
c
is
NotImplemented
:
return
c
return
c
<
0
def
__le__
(
self
,
other
):
c
=
self
.
_
_cmp__
(
other
)
c
=
self
.
_
cmp
(
other
)
if
c
is
NotImplemented
:
return
c
return
c
<=
0
def
__gt__
(
self
,
other
):
c
=
self
.
_
_cmp__
(
other
)
c
=
self
.
_
cmp
(
other
)
if
c
is
NotImplemented
:
return
c
return
c
>
0
def
__ge__
(
self
,
other
):
c
=
self
.
_
_cmp__
(
other
)
c
=
self
.
_
cmp
(
other
)
if
c
is
NotImplemented
:
return
c
return
c
>=
0
...
...
@@ -91,7 +91,7 @@ class Version:
# (if not identical to) the string supplied to parse
# __repr__ (self) - generate Python code to recreate
# the instance
# _
_cmp__
(self, other) - compare two version numbers ('other' may
# _
cmp
(self, other) - compare two version numbers ('other' may
# be an unparsed version string, or another
# instance of your version class)
...
...
@@ -169,30 +169,39 @@ class StrictVersion (Version):
return vstring
def _
_cmp__
(self, other):
def _
cmp
(self, other):
if isinstance(other, str):
other = StrictVersion(other)
compare = cmp(self.version, other.version)
if (compare == 0): # have to compare prerelease
# case 1: neither has prerelease; they'
re
equal
# case 2: self has prerelease, other doesn't; other is greater
# case 3: self doesn't have prerelease, other does: self is greater
# case 4: both have prerelease: must compare them!
if self.version != other.version:
# numeric versions don'
t
match
# prerelease stuff doesn't matter
if
self
.
version
<
other
.
version
:
return
-
1
else
:
return
1
if
(
not
self
.
prerelease
and
not
other
.
prerelease
):
# have to compare prerelease
# case 1: neither has prerelease; they're equal
# case 2: self has prerelease, other doesn't; other is greater
# case 3: self doesn't have prerelease, other does: self is greater
# case 4: both have prerelease: must compare them!
if
(
not
self
.
prerelease
and
not
other
.
prerelease
):
return
0
elif
(
self
.
prerelease
and
not
other
.
prerelease
):
return
-
1
elif
(
not
self
.
prerelease
and
other
.
prerelease
):
return
1
elif
(
self
.
prerelease
and
other
.
prerelease
):
if
self
.
prerelease
==
other
.
prerelease
:
return
0
elif
(
self
.
prerelease
and
not
other
.
prerelease
)
:
elif
self
.
prerelease
<
other
.
prerelease
:
return
-
1
el
if
(
not
self
.
prerelease
and
other
.
prerelease
)
:
el
se
:
return
1
elif
(
self
.
prerelease
and
other
.
prerelease
):
return
cmp
(
self
.
prerelease
,
other
.
prerelease
)
else
:
# numeric versions don't match --
return
compare
# prerelease stuff doesn't matter
else
:
assert
False
,
"never get here"
# end class StrictVersion
...
...
@@ -325,7 +334,7 @@ class LooseVersion (Version):
return
"LooseVersion ('%s')"
%
str
(
self
)
def
_
_cmp__
(
self
,
other
):
def
_
cmp
(
self
,
other
):
if
isinstance
(
other
,
str
):
other
=
LooseVersion
(
other
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment