[issue41904] datetime.datetime.today makes no sense and should be removed

2020-10-14 Thread Damian Yurzola


Damian Yurzola  added the comment:

Sorry I got my "current" wrong and I can't find the edit button
Here again:


> "How long is it until Christmas?"

# Current implementation
In [23]: datetime.datetime(2020, 12, 25) - datetime.datetime.today()
Out[23]: datetime.timedelta(days=71, seconds=53018, microseconds=941806)

# Hassan's
In [16]: datetime.datetime(2020, 12, 25) - 
datetime.datetime(datetime.datetime.today().year, 
datetime.datetime.today().month, datetime.datetime.today().day)
Out[16]: datetime.timedelta(days=72)

--

___
Python tracker 
<https://bugs.python.org/issue41904>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41904] datetime.datetime.today makes no sense and should be removed

2020-10-14 Thread Damian Yurzola


Damian Yurzola  added the comment:

It took me a while to collect my thoughts but here you go.

Advanced users don't have a problem. They'll trade in date or datetime objects 
explicitly. The "proof" is I could not find any github repo with more than one 
start that'll call datetime.today().

The less advanced users are sometime doing datetime.today and then all kinds of 
weird things.

HassanAbouelela has a good point: datetime.today() is a straight forward way to 
get today in a datetime object.


On the topic of:

> "How long is it until Christmas?"

# Current
In [7]: datetime.datetime.today() - datetime.datetime.now()
Out[7]: datetime.timedelta(days=-1, seconds=86399, microseconds=91)

# Hassan's
In [16]: datetime.datetime(2020, 12, 25) - 
datetime.datetime(datetime.datetime.today().year, 
datetime.datetime.today().month, datetime.datetime.today().day)
Out[16]: datetime.timedelta(days=72)


Optimizing for the less advanced user, I believe Hassan's proposal yields the 
more intuitive result.

--

___
Python tracker 
<https://bugs.python.org/issue41904>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41904] datetime.datetime.today makes no sense and should be removed

2020-10-13 Thread Damian Yurzola


Damian Yurzola  added the comment:

I searched all of github and there seem to be ~350K entries for datetime.today
I think this supports steven.daprano point against removal.

I could not spot any major library in a quick cursory look.

However I do see many calls that look a lot like they should have been

datetime.date.today rather than datetime.datetime.today.

You see people basically dropping the hours, minutes, secs.

And you also see people doing date math on datetime.date.today which will 
result in different answers through out the day.

I like HassanAbouelela's idea that datetime.datetime.today should return   an 
arbitrary fixed time rather than an arbitrary variable time.

--

___
Python tracker 
<https://bugs.python.org/issue41904>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41904] datetime.datetime.today makes no sense and should be removed

2020-10-01 Thread Damian Yurzola


Damian Yurzola  added the comment:

Thanks for your prompt answer Steven.

I was inspired to file this bug after reading through a multiplicity of bugs 
introduced by folks confused by the library's behavior. So there's good 
precedent.

While granted, the documentation is explicit and the inheritance chain 
substantiates it. There's nothing more explicit than the function/type names 
and saying datetime.today() brings, as you say, arbitrary time to the 
conversation. Which I claim, subjectively, that it should not.


Gratuitous breakage, is debatable. It would not be the first or last. It could 
be a chance to remove a lot of code that works around potentially incorrect 
mental models.

But since both points are to some extent subjective. I'm OK to have left this 
on the record and move on.


What do you say about the unnecessarily redefined properties?

Lines Lib/datetime.py#L1606 to datetime.py#L1620

--

___
Python tracker 
<https://bugs.python.org/issue41904>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41904] datetime.datetime.today makes no sense and should be removed

2020-10-01 Thread Damian Yurzola


New submission from Damian Yurzola :

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 
<https://bugs.python.org/issue41904>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40033] Just defined class missing from scope

2020-03-23 Thread Damian Yurzola


Change by Damian Yurzola :


--
versions: +Python 3.7

___
Python tracker 
<https://bugs.python.org/issue40033>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40033] Just defined class missing from scope

2020-03-21 Thread Damian Yurzola


Damian Yurzola  added the comment:

This is even a better example:

Level1A is available to inherit from, but not to type with.

Example:

from typing import List


class Level0A:
pass


class Level0B:
class Level1A:
pass

class Level1B(Level1A):
pass

class Level1C:
test: Level1A

--

___
Python tracker 
<https://bugs.python.org/issue40033>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40033] Just defined class missing from scope

2020-03-21 Thread Damian Yurzola


New submission from Damian Yurzola :

In the following example the last line throws as 'NameError: name 'Level1A' is 
not defined' for both 3.7 and 3.8

I assumed that Level1A should already be in scope while defining the insides of 
Level1B. But it isn't.
Is this a bug, or am I missing something?


from typing import List, Union


class Level0A:
pass


class Level0B:
class Level1A:
subs: List[Level0A]

class Level1B:
subs: List[Level1A]

--
components: Interpreter Core
messages: 364759
nosy: yurzo
priority: normal
severity: normal
status: open
title: Just defined class missing from scope
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue40033>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37742] logging.getLogger accepts name='root' leading to confusion

2019-08-01 Thread Damian Yurzola


New submission from Damian Yurzola :

'root' should be a reserved name to avoid this:

>>> import logging
>>> a = logging.getLogger()
>>> b = logging.getLogger('root')
>>> a.name
'root'
>>> b.name
'root'
>>> a is b
False

--
components: Library (Lib)
messages: 348877
nosy: yurzo
priority: normal
severity: normal
status: open
title: logging.getLogger accepts name='root' leading to confusion
type: enhancement
versions: Python 3.9

___
Python tracker 
<https://bugs.python.org/issue37742>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com