typeshed
typeshed copied to clipboard
Relativedelta `__rsub__` doesn't respect subclasses of datetime
Given this sample case:
from datetime import datetime
from dateutil.relativedelta import relativedelta
class MyDateTime(datetime):
pass
d = MyDateTime.now()
x = d - relativedelta(days=1)
print(type(x))
# reveal_type(x)
results in Python:
<class '__main__.MyDateTime'>
and mypy reports:
test.py:10: note: Revealed type is "datetime.datetime"
However, I'd expect MyDateTime as type here. I'm guessing the generic isn't correct here?
With understanding of TypeVar and it's effects on inheritance. Should it be adjusted to the following?
_DateT = TypeVar("_DateT", bound=date)
Given that datetime inherits from date already?