Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
d94a65a0
Commit
d94a65a0
authored
Sep 25, 2017
by
Serhiy Storchaka
Committed by
GitHub
Sep 25, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-25732: Make functools.total_ordering implementing __ne__. (#3748)
Patch by Raymond Hettinger.
parent
5f5da728
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
2 deletions
+61
-2
Lib/functools.py
Lib/functools.py
+7
-2
Lib/test/test_functools.py
Lib/test/test_functools.py
+53
-0
Misc/NEWS.d/next/Library/2017-09-25-13-10-08.bpo-25732.RWWgzg.rst
...S.d/next/Library/2017-09-25-13-10-08.bpo-25732.RWWgzg.rst
+1
-0
No files found.
Lib/functools.py
View file @
d94a65a0
...
...
@@ -55,23 +55,28 @@ def total_ordering(cls):
convert
=
{
'__lt__'
:
[(
'__gt__'
,
lambda
self
,
other
:
not
(
self
<
other
or
self
==
other
)),
(
'__le__'
,
lambda
self
,
other
:
self
<
other
or
self
==
other
),
(
'__ne__'
,
lambda
self
,
other
:
not
self
==
other
),
(
'__ge__'
,
lambda
self
,
other
:
not
self
<
other
)],
'__le__'
:
[(
'__ge__'
,
lambda
self
,
other
:
not
self
<=
other
or
self
==
other
),
(
'__lt__'
,
lambda
self
,
other
:
self
<=
other
and
not
self
==
other
),
(
'__ne__'
,
lambda
self
,
other
:
not
self
==
other
),
(
'__gt__'
,
lambda
self
,
other
:
not
self
<=
other
)],
'__gt__'
:
[(
'__lt__'
,
lambda
self
,
other
:
not
(
self
>
other
or
self
==
other
)),
(
'__ge__'
,
lambda
self
,
other
:
self
>
other
or
self
==
other
),
(
'__ne__'
,
lambda
self
,
other
:
not
self
==
other
),
(
'__le__'
,
lambda
self
,
other
:
not
self
>
other
)],
'__ge__'
:
[(
'__le__'
,
lambda
self
,
other
:
(
not
self
>=
other
)
or
self
==
other
),
(
'__gt__'
,
lambda
self
,
other
:
self
>=
other
and
not
self
==
other
),
(
'__ne__'
,
lambda
self
,
other
:
not
self
==
other
),
(
'__lt__'
,
lambda
self
,
other
:
not
self
>=
other
)]
}
roots
=
set
(
dir
(
cls
))
&
set
(
convert
)
defined_methods
=
set
(
dir
(
cls
))
roots
=
defined_methods
&
set
(
convert
)
if
not
roots
:
raise
ValueError
(
'must define at least one ordering operation: < > <= >='
)
root
=
max
(
roots
)
# prefer __lt__ to __le__ to __gt__ to __ge__
for
opname
,
opfunc
in
convert
[
root
]:
if
opname
not
in
root
s
:
if
opname
not
in
defined_method
s
:
opfunc
.
__name__
=
opname
opfunc
.
__doc__
=
getattr
(
int
,
opname
).
__doc__
setattr
(
cls
,
opname
,
opfunc
)
...
...
Lib/test/test_functools.py
View file @
d94a65a0
...
...
@@ -600,6 +600,59 @@ class TestTotalOrdering(unittest.TestCase):
with
self
.
assertRaises
(
TypeError
):
TestTO
(
8
)
<=
()
def
test_bug_25732
(
self
):
@
functools
.
total_ordering
class
A
:
def
__init__
(
self
,
value
):
self
.
value
=
value
def
__gt__
(
self
,
other
):
return
self
.
value
>
other
.
value
def
__eq__
(
self
,
other
):
return
self
.
value
==
other
.
value
self
.
assertTrue
(
A
(
1
)
!=
A
(
2
))
self
.
assertFalse
(
A
(
1
)
!=
A
(
1
))
@
functools
.
total_ordering
class
A
(
object
):
def
__init__
(
self
,
value
):
self
.
value
=
value
def
__gt__
(
self
,
other
):
return
self
.
value
>
other
.
value
def
__eq__
(
self
,
other
):
return
self
.
value
==
other
.
value
self
.
assertTrue
(
A
(
1
)
!=
A
(
2
))
self
.
assertFalse
(
A
(
1
)
!=
A
(
1
))
@
functools
.
total_ordering
class
A
:
def
__init__
(
self
,
value
):
self
.
value
=
value
def
__gt__
(
self
,
other
):
return
self
.
value
>
other
.
value
def
__eq__
(
self
,
other
):
return
self
.
value
==
other
.
value
def
__ne__
(
self
,
other
):
raise
RuntimeError
(
self
,
other
)
with
self
.
assertRaises
(
RuntimeError
):
A
(
1
)
!=
A
(
2
)
with
self
.
assertRaises
(
RuntimeError
):
A
(
1
)
!=
A
(
1
)
@
functools
.
total_ordering
class
A
(
object
):
def
__init__
(
self
,
value
):
self
.
value
=
value
def
__gt__
(
self
,
other
):
return
self
.
value
>
other
.
value
def
__eq__
(
self
,
other
):
return
self
.
value
==
other
.
value
def
__ne__
(
self
,
other
):
raise
RuntimeError
(
self
,
other
)
with
self
.
assertRaises
(
RuntimeError
):
A
(
1
)
!=
A
(
2
)
with
self
.
assertRaises
(
RuntimeError
):
A
(
1
)
!=
A
(
1
)
def
test_main
(
verbose
=
None
):
test_classes
=
(
TestPartial
,
...
...
Misc/NEWS.d/next/Library/2017-09-25-13-10-08.bpo-25732.RWWgzg.rst
0 → 100644
View file @
d94a65a0
`functools.total_ordering()` now implements the `__ne__` method.
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