[Python-Dev] Can we improve support for abstract base classes with desciptors

Darren Dale dsdale24 at gmail.com
Thu Jun 9 00:51:52 CEST 2011

On Wed, Jun 8, 2011 at 11:55 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On Thu, Jun 9, 2011 at 1:01 AM, Darren Dale <dsdale24 at gmail.com> wrote:
> [snip excellent analysis of the problem]
> I have some suggestions regarding a few details of your current code,
> but your basic proposal looks sound to me.
> I would tweak __new__ along the following lines though:

Thank you, I agree. Concerning the following block:

>       def get_abstract_names(ns):
>           names = []
>           for item in ns.items():
>               names.extend(get_abstract_names_for_item(item))
>           return names
>       abstract_names = get_abstract_names(namespace.items())

That should be "get_abstract_names(namespace)", since ns.items() gets
called again in the for loop. I think the get_abstract_names function
isn't needed though, since it is only ever called that one time. Any
reason not replace the above block with::

        abstract_names = []
        for item in namespace.items():

>       for base in bases:
>           for name in getattr(base, "__abstractmethods__", ()):
>               # CHANGE 4: Using rpartition better tolerates weird
> naming in the metaclass
>               # (weird naming in descriptors will still blow up in
> the earlier search for abstract names)

Could you provide an example of weird naming?


More information about the Python-Dev mailing list