Message243133
Hmm Ok. You are right i can do the following:
from collections import UserDict
from abc import ABCMeta
class MetaMyDict(ABCMeta):
@classmethod
def __prepare__(cls, name, bases, **kwargs):
return {}
def __new__(mcls, name, bases, namespace, **kwds):
return super().__new__(mcls, name, bases, namespace)
def __init__(cls, name, bases, namespace, **kargs):
return super().__init__(name, bases, namespace)
class MyDict(UserDict, metaclass=MetaMyDict, bar='baz'):
pass
dictionary = MyDict()
But I guess i would have expected a core lib library to be consistent with the data model https://docs.python.org/3.4/reference/datamodel.html#preparing-the-class-namespace. As it stands an end user can't get a subclass of ABCMeta to work with the same **kwargs interface without creating a custom metaclass that strips it out before passing to ABCMeta.
Wouldn't it be much easier and technically correct for the core ABCMeta library to adopt the same interface contract for class creation introduced in python3? |
|
Date |
User |
Action |
Args |
2015-05-14 00:34:22 | trcarden | set | recipients:
+ trcarden, r.david.murray |
2015-05-14 00:34:22 | trcarden | set | messageid: <1431563662.24.0.827126550893.issue24183@psf.upfronthosting.co.za> |
2015-05-14 00:34:22 | trcarden | link | issue24183 messages |
2015-05-14 00:34:20 | trcarden | create | |
|