]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-49766: Make date-datetime comparison more symmetric and flexible (GH-114760)
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 11 Feb 2024 11:06:43 +0000 (13:06 +0200)
committerGitHub <noreply@github.com>
Sun, 11 Feb 2024 11:06:43 +0000 (13:06 +0200)
commitb1043607884d774acabd255ecdcebb159f76a2fb
tree4621a610aa02126372c5a23d5ee55d7c2d5a9f5d
parentd9d6909697501a2604d5895f9f88aeec61274ab0
gh-49766: Make date-datetime comparison more symmetric and flexible (GH-114760)

Now the special comparison methods like `__eq__` and `__lt__` return
NotImplemented if one of comparands is date and other is datetime
instead of ignoring the time part and the time zone or forcefully
return "not equal" or raise TypeError.

It makes comparison of date and datetime subclasses more symmetric
and allows to change the default behavior by overriding
the special comparison methods in subclasses.

It is now the same as if date and datetime was independent classes.
Doc/library/datetime.rst
Lib/_pydatetime.py
Lib/test/datetimetester.py
Misc/NEWS.d/next/Library/2024-01-30-22-10-50.gh-issue-49766.yulJL_.rst [new file with mode: 0644]
Modules/_datetimemodule.c