Vedran Čačić <ved...@gmail.com> added the comment:

It seems to me that what you're missing is that "class declarations" are still 
perfectly normal executable statements (in most other superficially similar 
programming languages, they are not). So, when you say

class A:
    b = []

it is actually executed, a new empty list is made, and named A.b. If you then 
construct a = A(), then a.b is that same object. It must be, you never made any 
other list in the process. So if you really want a.b to be a _different_ empty 
list, you have to make it at some point. The most obvious way to do it is just 
to copy the A.b --- that's why people usually talk about copying.

Your approach is different: it seems to me that you say, if A.b is a list, then 
make a new empty list, if it is a set, then make a new empty set, and if it is 
a dict, then make a new empty dict. Not to mention that it feels very weird 
when having e.g.

class A:
    b = [4]

(-:, it doesn't take into account any other types. Which leads to another your 
problem, the one of perspective. Lists, sets and dicts are not that "common 
case" as you seem to think. Yes, they are in the beginners' code -- and that's 
why current dataclass implementation flags them as errors, since it's quite 
possible that people who write such things don't actually understand how Python 
is executed. But specialcasing them to actually do something useful would be 
the wrong thing to do, since it would incentivize people who should know 
better, back into using those simple types. I think it is shown in the 
discussion mentioned.

----------

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

Reply via email to