New submission from René Hernández Remedios:

In the documentation for the supported arithmetic operations for a datetime 
object, there is the following note, among other:

datetime2 = datetime1 - timedelta

Comment:
Computes the datetime2 such that datetime2 + timedelta == datetime1. As for 
addition, the result has the same tzinfo attribute as the input datetime, and 
no time zone adjustments are done even if the input is aware. This isn’t quite 
equivalent to datetime1 + (-timedelta), because -timedelta in isolation can 
overflow in cases where datetime1 - timedelta does not.

While reading the source code for __sub__ operation I found in the first few 
lines:

Line 1885:
def __sub__(self, other):
    "Subtract two datetimes, or a datetime and a timedelta."
    if not isinstance(other, datetime):
        if isinstance(other, timedelta):
            return self + -other
        return NotImplemented

Is the documentation in contradiction with the actual implementation?

----------
messages: 294787
nosy: René Hernández Remedios
priority: normal
severity: normal
status: open
title: Documentation for datetime substract operation incorrect?
versions: Python 3.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30516>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to