I have a couple classes extending builtin datetime.*
Is there any good reason to not overload + (MyTime.__radd___) so MyDate + MyTime returns a MyDateTime?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This would generally be frowned upon because you’re really combining rather than adding; this is why the actual datetime library has a combine method rather than using addition in this way.
I’m not aware of any other cases in Python where
<instance of TypeA> + <instance of TypeB>produces<instance of TypeC>. Thus, the Principle of least astonishment suggests that you should simply provide acombinemethod rather than overload addition.