This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author veky
Recipients anthony, eric.smith, veky
Date 2019-11-14.04:24:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1573705491.06.0.737012422431.issue38758@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-11-14 04:24:51vekysetrecipients: + veky, eric.smith, anthony
2019-11-14 04:24:51vekysetmessageid: <1573705491.06.0.737012422431.issue38758@roundup.psfhosted.org>
2019-11-14 04:24:51vekylinkissue38758 messages
2019-11-14 04:24:50vekycreate