Integers.py: How can I resolve the cyclic importing issue for overloads?

90 views
Skip to first unread message

Joseph Mehdiyev

unread,
Mar 26, 2026, 5:21:05 AM (2 days ago) Mar 26
to sympy
Hey all,
I was trying to fix the Issue:8444, and I was mainly following Oscar's comment on this:
> The special method `floor.__lt__` is used in `floor(x) < y` but `Expr.__lt__` is used for `y < floor(x)`. The special methods `__lt__` etc should be removed from `floor` and in fact all `Expr` subclasses because the logic needs to be in the `is_lt/is_ge` functions which are used by all of the `Relational` subclasses (`StrictLessThan` etc). The only possible reason for defining an `__lt__` method in an `Expr` subclass is to make a fast path that can bypass the full `StrictLessThan/is_lt` mechanism in simple cases. All of the logic needs to be implemented in`is_ge` to make things consistent.
>
> The `__lt__` method should be removed and `_eval_is_ge` should have an overload for `floor` to handle this case instead.

Overloading ' _eval_is_ge' for integers classes raises ambigious behaviour on [Expr, AccumulationBounds] and other similar pairs. Problem is that I cannot fix the warning as importing the AccumulationBound makes a circular import issue in the integers.py file.

I can bypass this by writing all the overloads  (Which I assume is not a right choice design wise) on the accumulationbounds.py file. But, then even though the warnings are gone and the issue 8444 fixes when I try the tests manually in my terminal, the exact tests still fail from bin/tests relational.py (I assume because of the the place of the overloads)

Can someone explain me how to fix this? Am I doing something wrong here?


Joseph Mehdiyev

unread,
Mar 26, 2026, 8:49:24 AM (2 days ago) Mar 26
to sympy
I will make a PR with the ambiguous behavior warnings included (unless I fix it until then), as I feel like explanation here is not sufficient to explain my problem. Hopefully someone will help me there.

Also, the tests already written for the 8444 that fails are mathematically wrong, that is why they are failing! XFAIL test x is defined as complex number (floor is not defined for complex x), and floor, ceiling are not defined for complex numbers.
Reply all
Reply to author
Forward
0 new messages