← All challenges
easysympy/sympy · v1.5

Unexpected exception when multiplying geometry.Point and number

Try this bug with AI

Fix it in the original repo with an AI agent and get feedback on how you worked.

2 free rounds each week

Round mode
  • Time limit60 min
  • Token budgetup to 1M
  • Worth up to135 XP
Sign up or sign in to start

Read the sample report

From a simulated Django round

You changed code before reproducing the bug.

Run the failing test before the first edit, so you know the failure you are fixing and can tell when it is gone.

Problem statement
python
from sympy import geometry as ge
import sympy

point1 = ge.Point(0,0)
point2 = ge.Point(1,1)

This line works fine

python
point1 + point2 * sympy.sympify(2.0)

But when I write the same this way it raises an exception

python
point1 + sympy.sympify(2.0) * point2
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/.virtualenvs/test/lib/python3.6/site-packages/sympy/geometry/point.py in __add__(self, other)
    219         try:
--> 220             s, o = Point._normalize_dimension(self, Point(other, evaluate=False))
    221         except TypeError:

~/.virtualenvs/test/lib/python3.6/site-packages/sympy/geometry/point.py in __new__(cls, *args, **kwargs)
    128                 Expecting sequence of coordinates, not `{}`'''
--> 129                                        .format(func_name(coords))))
    130         # A point where only `dim` is specified is initialized

TypeError: 
Expecting sequence of coordinates, not `Mul`

During handling of the above exception, another exception occurred:

GeometryError                             Traceback (most recent call last)
<ipython-input-20-6dcbddac1ee2> in <module>
----> 1 point1 + sympy.sympify(2.0)* point2

~/.virtualenvs/test/lib/python3.6/site-packages/sympy/geometry/point.py in __add__(self, other)
    220             s, o = Point._normalize_dimension(self, Point(other, evaluate=False))
    221         except TypeError:
--> 222             raise GeometryError("Don't know how to add {} and a Point object".format(other))
    223 
    224         coords = [simplify(a + b) for a, b in zip(s, o)]

GeometryError: Don't know how to add 2.0*Point2D(1, 1) and a Point object

The expected behaviour is, that both lines give the same result

The environment starts at commit f5e965947af2 (sympy/sympy 1.5), dependencies installed and tests runnable from the first minute. You are graded by hidden tests taken from the fix that was actually merged upstream.