[New-bugs-announce] [issue30516] Documentation for datetime substract operation incorrect?

René Hernández Remedios report at bugs.python.org
Tue May 30 17:22:13 EDT 2017

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

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 <report at bugs.python.org>

More information about the New-bugs-announce mailing list