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
71b7fac0
Commit
71b7fac0
authored
Mar 27, 2010
by
Mark Dickinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make Fraction to complex comparisons with <=, <, >= or > raise TypeError.
parent
355adc5a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
4 deletions
+19
-4
Lib/fractions.py
Lib/fractions.py
+4
-2
Lib/test/test_fractions.py
Lib/test/test_fractions.py
+15
-2
No files found.
Lib/fractions.py
View file @
71b7fac0
...
...
@@ -511,8 +511,10 @@ class Fraction(Rational):
if
isinstance
(
other
,
Rational
):
return
op
(
self
.
_numerator
*
other
.
denominator
,
self
.
_denominator
*
other
.
numerator
)
if
isinstance
(
other
,
numbers
.
Complex
)
and
other
.
imag
==
0
:
other
=
other
.
real
# comparisons with complex should raise a TypeError, for consistency
# with int<->complex, float<->complex, and complex<->complex comparisons.
if
isinstance
(
other
,
complex
):
raise
TypeError
(
"no ordering relation is defined for complex numbers"
)
if
isinstance
(
other
,
float
):
if
math
.
isnan
(
other
)
or
math
.
isinf
(
other
):
return
op
(
0.0
,
other
)
...
...
Lib/test/test_fractions.py
View file @
71b7fac0
...
...
@@ -473,8 +473,21 @@ class FractionTest(unittest.TestCase):
def
testBigComplexComparisons
(
self
):
self
.
assertFalse
(
F
(
10
**
23
)
==
complex
(
10
**
23
))
self
.
assertTrue
(
F
(
10
**
23
)
>
complex
(
10
**
23
))
self
.
assertFalse
(
F
(
10
**
23
)
<=
complex
(
10
**
23
))
self
.
assertRaises
(
TypeError
,
operator
.
gt
,
F
(
10
**
23
),
complex
(
10
**
23
))
self
.
assertRaises
(
TypeError
,
operator
.
le
,
F
(
10
**
23
),
complex
(
10
**
23
))
x
=
F
(
3
,
8
)
z
=
complex
(
0.375
,
0.0
)
w
=
complex
(
0.375
,
0.2
)
self
.
assertTrue
(
x
==
z
)
self
.
assertFalse
(
x
!=
z
)
self
.
assertFalse
(
x
==
w
)
self
.
assertTrue
(
x
!=
w
)
for
op
in
operator
.
lt
,
operator
.
le
,
operator
.
gt
,
operator
.
ge
:
self
.
assertRaises
(
TypeError
,
op
,
x
,
z
)
self
.
assertRaises
(
TypeError
,
op
,
z
,
x
)
self
.
assertRaises
(
TypeError
,
op
,
x
,
w
)
self
.
assertRaises
(
TypeError
,
op
,
w
,
x
)
def
testMixedEqual
(
self
):
self
.
assertTrue
(
0.5
==
F
(
1
,
2
))
...
...
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