On Thu, Jun 9, 2011 at 8:51 AM, Darren Dale <dsdal...@gmail.com> wrote: > 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))
Nope, inlining that part makes sense. >> 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? >>> class C(object): ... pass ... >>> setattr(C, 'weird.name', staticmethod(int)) >>> c = C() >>> c.weird.name Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'C' object has no attribute 'weird' >>> c.weird.name Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'C' object has no attribute 'weird' >>> getattr(c, 'weird.name')() 0 This is definitely something that could legitimately be dismissed as "well, don't do that then" (particularly since similarly weird names on the descriptors will still break). However, I also prefer the way partition based code reads over split-based code, so I still like the modified version. Full tolerance for weird naming would require storing 2-tuples in __abstractmethods__ which would cause a whole new set of problems and isn't worth the hassle. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com