8000 gh-102840: Fix confused traceback when `floordiv` or `mod` operations happens between `Fraction` and `complex` objects by Eclips4 · Pull Request #102842 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-102840: Fix confused traceback when floordiv or mod operations happens between Fraction and complex objects #102842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 10, 2024
Prev Previous commit
Next Next commit
Apply suggestions from Serhiy
  • Loading branch information
Eclips4 committed Feb 10, 2024
commit 2e75353e3a2f03252c541e6fe07bab3506f4cdd7
3 changes: 2 additions & 1 deletion Lib/fractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ def __format__(self, format_spec, /):
f"for object of type {type(self).__name__!r}"
)

def _operator_fallbacks(monomorphic_operator, fallback_operator, handle_complex=False):
def _operator_fallbacks(monomorphic_operator, fallback_operator,
handle_complex=False):
"""Generates forward and reverse operators given a purely-rational
operator and a function from the operator module.

Expand Down
14 changes: 7 additions & 7 deletions Lib/test/test_fractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,26 +1295,26 @@ def test_complex_handling(self):

a = F(1, 2)
b = 1j
message = "unsupported operand type(s) for %s: %s and %s"
message = "unsupported operand type(s) for %s: '%s' and '%s'"
# test forward
self.assertRaisesMessage(TypeError,
message % ("%", "'Fraction'", "'complex'"),
message % ("%", "Fraction", "complex"),
operator.mod, a, b)
self.assertRaisesMessage(TypeError,
message % ("//", "'Fraction'", "'complex'"),
message % ("//", "Fraction", "complex"),
operator.floordiv, a, b)
self.assertRaisesMessage(TypeError,
message % ("divmod()", "'Fraction'", "'complex'"),
message % ("divmod()", "Fraction", "complex"),
divmod, a, b)
# test reverse
self.assertRaisesMessage(TypeError,
message % ("%", "'complex'", "'Fraction'"),
message % ("%", "complex", "Fraction"),
operator.mod, b, a)
self.assertRaisesMessage(TypeError,
message % ("//", "'complex'", "'Fraction'"),
message % ("//", "complex", "Fraction"),
operator.floordiv, b, a)
self.assertRaisesMessage(TypeError,
message % ("divmod()", "'complex'", "'Fraction'"),
message % ("divmod()", "complex", "Fraction"),
divmod, b, a)


Expand Down
0