Re: [Python-ideas] Are we supposed to be able to have our own class dictionary in python 3?

Thanks Daniel, I found my answer here (using your link): https://docs.python.org/3/reference/datamodel.html#preparing-the-class-names... """ When a new class is created by type.__new__, the object provided as the namespace parameter is copied to a new ordered mapping and the original object is discarded. """ Therefore the answer seems to be that https://www.python.org/dev/peps/pep-3115/ needs to be updated & fixed. Replace the following: """ def __new__(cls, name, bases, classdict): # Note that we replace the classdict with a regular # dict before passing it to the superclass, so that we # don't continue to record member names after the class # has been created. result = type.__new__(cls, name, bases, dict(classdict)) result.member_names = classdict.member_names return result """ With: """ def __new__(cls, name, bases, classdict): result = type.__new__(cls, name, bases, classdict) result.member_names = classdict.member_names return result """ Removing the incorrect comments & the copying of `classdict` I will go file a bug report to that effect. Thanks, Joy Diamond. On Sat, Nov 3, 2018 at 7:55 PM Daniel Moisset <dfmoisset@gmail.com> wrote:

I think the documentation is correct but you misinterpreted the intent of that code. The code you're quoting, which is an example, is not about ending up with a custom dict within the instance, the intent of the author was just to captur the memeber_names list. So what it does for that is customizing the class dict in prepare(), but then in __init__ it *intentionally* converts it to a regular dict after extracting the member_names. The goal of the example is ending up with instances with regular attribute dicts but an extra member_names attributes, while I think that you're looking for to end up with a custom attribute dict (so in *your* case, you do not need to do the copying) On Sun, 4 Nov 2018 at 00:03, Amit Green <amit.mixie@gmail.com> wrote:

I think the documentation is correct but you misinterpreted the intent of that code. The code you're quoting, which is an example, is not about ending up with a custom dict within the instance, the intent of the author was just to captur the memeber_names list. So what it does for that is customizing the class dict in prepare(), but then in __init__ it *intentionally* converts it to a regular dict after extracting the member_names. The goal of the example is ending up with instances with regular attribute dicts but an extra member_names attributes, while I think that you're looking for to end up with a custom attribute dict (so in *your* case, you do not need to do the copying) On Sun, 4 Nov 2018 at 00:03, Amit Green <amit.mixie@gmail.com> wrote:
participants (2)
-
Amit Green
-
Daniel Moisset