[issue41904] datetime.datetime.today makes no sense and should be removed
Damian Yurzola
report at bugs.python.org
Thu Oct 1 11:54:18 EDT 2020
New submission from Damian Yurzola <damian at yurzola.net>:
Last night I discovered we have datetime.datetime.today alongside
datetime.datetime.now and datetime.date.today.
- datetime.now
- date.today
Both make semantic sense.
datetime.datetime.today returns a datetime, which make no semantic sense and causes confusion.
On further inspection of the code, this is due to the fact that datetime inherits from date.
so datetime.today is practically an implementation of datetime.now minus the "tz".
I think we should implement a datetime.today only to rise an AttributeError or some other way to stop people from using the wrong semantic mental model.
We'd also need to remove the documentation entry:
https://docs.python.org/3/library/datetime.html#datetime.datetime.today
>From this inspection we also find that:
datetime.hour/minute/second are unnecessarily redefined.
lines Lib/datetime.py#L1606 to datetime.py#L1620
could be removed without any ill effect.
date.today:
https://github.com/python/cpython/blob/256e54acdbdb26745d4bbb5cf366454151e42773/Lib/datetime.py#L833
https://docs.python.org/3/library/datetime.html#datetime.datetime.today
----------
components: Library (Lib)
messages: 377768
nosy: yurzo
priority: normal
severity: normal
status: open
title: datetime.datetime.today makes no sense and should be removed
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41904>
_______________________________________
More information about the Python-bugs-list
mailing list