Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
fromfractionsimportFractiona=Fraction(1,2)b=a//1j>Traceback (mostrecentcalllast):File"C:\Users\KIRILL-1\CLionProjects\cpython\example.py",line5,in<module>b=a//1j~~^^~~~File"C:\Users\KIRILL-1\AppData\Local\Programs\Python\Python311\Lib\fractions.py",line363,inforwardreturnfallback_operator(complex(a),b)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^TypeError:unsupportedoperand type(s)for//:'complex'and'complex'
This traceback really confused me.
However, it's easy to fix, just need change these lines:
Lines 620 to 621 in5e6661b
| elifisinstance(b,complex): | |
| returnfallback_operator(complex(a),b) |
To this:
elifisinstance(b,complex):try:returnfallback_operator(complex(a),b)exceptTypeError:raiseTypeError("unsupported operand type(s) for %r: %r and %r"% (fallback_operator.__name__,type(a).__qualname__,type(b).__qualname__) )fromNone
So, after that, we have a pretty nice traceback:
Traceback (mostrecentcalllast):File"C:\Users\KIRILL-1\CLionProjects\cpython\example.py",line5,in<module>b=a//1j~~^^~~~File"C:\Users\KIRILL-1\CLionProjects\cpython\Lib\fractions.py",line624,inforwardraiseTypeError(TypeError:unsupportedoperandtype(s)for'floordiv':'Fraction'and'complex'
But, here a one problem - would be nice to have in traceback originally// instead offloordiv. I have no idea how to do it, without create a mapping with names. Theoretically - we can add a special attribute for it inoperator, but it should be a another discussion.