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
655d583a
Commit
655d583a
authored
Jul 10, 2008
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue 3287: Raise correct exception for float inputs.
parent
14ff9943
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
7 deletions
+9
-7
Lib/fractions.py
Lib/fractions.py
+5
-3
Lib/test/test_fractions.py
Lib/test/test_fractions.py
+4
-4
No files found.
Lib/fractions.py
View file @
655d583a
...
...
@@ -96,9 +96,11 @@ class Fraction(Rational):
if
denominator
==
0
:
raise
ZeroDivisionError
(
'Fraction(%s, 0)'
%
numerator
)
numerator
=
numerator
.
__index__
()
denominator
=
denominator
.
__index__
()
try
:
numerator
=
numerator
.
__index__
()
denominator
=
denominator
.
__index__
()
except
AttributeError
:
raise
TypeError
(
'Numerator and denominator must support __index__.'
)
g
=
gcd
(
numerator
,
denominator
)
self
.
_numerator
=
numerator
//
g
self
.
_denominator
=
denominator
//
g
...
...
Lib/test/test_fractions.py
View file @
655d583a
...
...
@@ -62,11 +62,11 @@ class FractionTest(unittest.TestCase):
self
.
assertRaisesMessage
(
ZeroDivisionError
,
"Fraction(12, 0)"
,
F
,
12
,
0
)
self
.
assertRaises
(
Attribut
eError
,
F
,
1.5
)
self
.
assertRaises
(
Attribut
eError
,
F
,
1.5
+
3j
)
self
.
assertRaises
(
Typ
eError
,
F
,
1.5
)
self
.
assertRaises
(
Typ
eError
,
F
,
1.5
+
3j
)
self
.
assertRaises
(
Attribut
eError
,
F
,
F
(
1
,
2
),
3
)
self
.
assertRaises
(
Attribut
eError
,
F
,
"3/2"
,
3
)
self
.
assertRaises
(
Typ
eError
,
F
,
F
(
1
,
2
),
3
)
self
.
assertRaises
(
Typ
eError
,
F
,
"3/2"
,
3
)
def
testFromString
(
self
):
self
.
assertEquals
((
5
,
1
),
_components
(
F
(
"5"
)))
...
...
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