[Python-Dev] Can we improve support for abstract base classes with desciptors (original) (raw)

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: [snip]

Thank you, I agree. Concerning the following block:

def getabstractnames(ns): names = [] for item in ns.items(): names.extend(getabstractnamesforitem(item)) return names

abstractnames = getabstractnames(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():
        abstract_names.extend(get_abstract_names_for_item(item))

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?

Darren



More information about the Python-Dev mailing list