mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Minor wordsmithing on docstring
This commit is contained in:
parent
38db364076
commit
2df20a3e08
1 changed files with 7 additions and 8 deletions
|
@ -193,18 +193,18 @@ class Rational(RationalAbc):
|
||||||
Rational, that means that we define __add__ and __radd__ as:
|
Rational, that means that we define __add__ and __radd__ as:
|
||||||
|
|
||||||
def __add__(self, other):
|
def __add__(self, other):
|
||||||
|
# Both types have numerators/denominator attributes,
|
||||||
|
# so do the operation directly
|
||||||
if isinstance(other, (int, long, Rational)):
|
if isinstance(other, (int, long, Rational)):
|
||||||
# Do the real operation.
|
|
||||||
return Rational(self.numerator * other.denominator +
|
return Rational(self.numerator * other.denominator +
|
||||||
other.numerator * self.denominator,
|
other.numerator * self.denominator,
|
||||||
self.denominator * other.denominator)
|
self.denominator * other.denominator)
|
||||||
# float and complex don't follow this protocol, and
|
# float and complex don't have those operations, but we
|
||||||
# Rational knows about them, so special case them.
|
# know about those types, so special case them.
|
||||||
elif isinstance(other, float):
|
elif isinstance(other, float):
|
||||||
return float(self) + other
|
return float(self) + other
|
||||||
elif isinstance(other, complex):
|
elif isinstance(other, complex):
|
||||||
return complex(self) + other
|
return complex(self) + other
|
||||||
else:
|
|
||||||
# Let the other type take over.
|
# Let the other type take over.
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
|
@ -219,7 +219,6 @@ class Rational(RationalAbc):
|
||||||
return float(other) + float(self)
|
return float(other) + float(self)
|
||||||
elif isinstance(other, Complex):
|
elif isinstance(other, Complex):
|
||||||
return complex(other) + complex(self)
|
return complex(other) + complex(self)
|
||||||
else:
|
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue