I have implemented a class TimeWindow
, which overloads __add__
, __sub__
and __contains__
.
These operations handle instances of TimeWindow, int, float
and return instances of TimeWindow
when appropriate.
Now, I understand that the +
, -
and in
operators when encountering foo + other
will invoke the proper functions when foo
is an instance of TimeWindow
and will fail when int
or float
are the first argument as the operation is unsupported by an int
or float
type.
My current solution is:
- Convert
int
andfloat
types to equivalentTimeWindow
type before the operation. - Ensure the first argument is
TimeWindow
type when possible.
I know of solutions such as this in other languages. Is there an equivalent solution to this in python?