-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
iterate is broken with subclasses of Interval #75
Comments
Hi Antoine, Thanks for reporting this issue! Would it be possible to have the code of your subclass? I don't see why |
That said, the proposed fix is worth to implement anyway, since it allows to avoid mixing object types anyway ;-) |
Could you check whether e49898c fixes the issue? I bypassed creating singleton instances (since the only reason to create singletons comes from a deprecated "feature"), so it should work :) |
Yes, this is what I said myself when I woke up this morning. The recursion is clearly in the comparaison operator. But not quite sure if/how it could be related on overwritting it... Anyway, my class is specialized to deal with datetime intervals. Here is the smallest simplified code I can provide that triggers the bug: import portion as P
import datetime as dt
class TimeExtent(P.Interval):
def __init__(self):
t0 = dt.datetime(2022,1,1)
t1 = dt.datetime(2022,1,2)
super().__init__(P.closedopen(t0,t1))
t=TimeExtent()
next(P.iterate(t, dt.datetime.resolution)) Antoine |
Thanks! I can reproduce the bug, and it is indeed fixed by the last commit. I don't know exactly what happened. I looked at Python's documentation for rich comparisons, and discovered something specific for subclasses I wasn't aware of:
That means when I'll change our definition of |
Version 2.3.1 will be available with the corresponding fix on PyPI in a few minutes. |
Good! BTW, this is completly unrelated, but you could also add a def __format__(self, spec):
return P.to_string(self, lambda v: ('{:'+spec+'}').format(v)) Best regards, Antoine |
That's something I already considered but I don't remember exactly why I decided not to implement it. :-) Can you open a new issue for this, so that we'll keep the related discussion in it and, depending on the fate of this issue, either it will be implemented or reasons for not doing so will be described somewhere? Thanks :-) |
Oh I remember : that's because format can also be used to define some padding/alignment and there's no easy way to apply this to infinities, leading to unexpected string rendering and "inconsistencies". |
Hi @adm271828 I've made several recent (and experimental) changes to Since you're the most recent user I know who already subclassed |
Hi Alexandre, I had a quick look. I don't know exactly what to say. On one hand the new feature is a step forward handling what you call discrete intervals (the use case you selected) and, as a side effect, exposes the On the other hand (please don't consider what follows as an offense), I have the feeling there is an initial design flaw and I'm not sure the choices and the used vocabulary is not a continuation of it. Let me try to explain this (from a library user perspective). Basicaly I see an instance of Of course the fact that their external (printed) representation is simplified is a bonus (much more readable for a user). And the fact I can add values to the set using comprehension (all values between It seems to me this was how the version The design in I agree the description of the library that you provide is ambiguous enough so that it can be claimed it was explicit: "The library provides data structure and operations for intervals". I'm not sure this is how that vast majority of users unterstood it. Back to the use case you selected, the underlying problem is to restrict the domain from which values can be taken, and to let Of course, Just my two cents... Best regards, Antoine |
Thanks for this feedback! ;-) |
Hi Alexandre,
in version 2.3.0, when using subclasses of Interval, iterate will lead to infinite recursion.
Seems to be because, in
iterate(...)
,exclude(value, i)
has becomeexclude(singleton(value),i)
where the singleton is an instance ofInterval
and not of the subclass being used. And the infinite recursion takes place in__lt__
operator that keeps calling itself it__gt__
has not been overwriten in the subclass.Possible fix: replace
singleton(value)
calls in exclude/include loops withinterval.__class__.from_atomic(Bound.CLOSED, value, value, Bound.CLOSED)
Great library BTW.
Best regards.
Antoine
The text was updated successfully, but these errors were encountered: