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 levkivskyi
Recipients Ricyteach, levkivskyi
Date 2018-03-30.21:02:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1522443730.54.0.467229070634.issue33190@psf.upfronthosting.co.za>
In-reply-to
Content
This is not a bug, but a misunderstanding:

* First, ABCMeta doesn't have `__prepare__`, it is just `type.__prepare__`
* Second, the third argument to `types.new_class` is called `kwds` for a reason. It is not a namespace like in `type` but the set of keywords in the equivalent class definition. For example:

types.new_class('Test', (A, B), {'metaclass': Meta, 'foo': 42})

id equivalent to

class Test(A, B, metaclass=Meta, foo=42):
    pass

If you want to populate the namespace, then you should use the fourth argument `exec_body` which should be a callable that takes newly created dictionary and populates it with items. For your case it should be:

C = new_class("C", (MyABC,), {}, exec_body=lambda ns: ns.update(namespace))

If you want to clarify the corresponding docstring, then please open a PR. Otherwise you can close the issue.
History
Date User Action Args
2018-03-30 21:02:10levkivskyisetrecipients: + levkivskyi, Ricyteach
2018-03-30 21:02:10levkivskyisetmessageid: <1522443730.54.0.467229070634.issue33190@psf.upfronthosting.co.za>
2018-03-30 21:02:10levkivskyilinkissue33190 messages
2018-03-30 21:02:10levkivskyicreate