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 methane
Recipients levkivskyi, methane
Date 2018-01-13.18:29:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
ABCMeta.__new__ calls `getattr(value, "__isabstractmethod__", False)` many times.

Since metaclass is used by subclasses, it checks all members of all subclasses (including concrete class).

But getattr() and hasattr() is inefficient when attribution is not found,
because it raises AttributeError and clear it internally.

I tried to bypass AttributeError when tp_getattro == PyObject_GenericGetAttr.
Here is quick micro benchmark:

$ ./python-patched -m perf timeit --compare-to=`pwd`/python-master -s 'def foo(): pass' 'hasattr(foo, "__isabstractmethod__")'python-master: ..................... 385 ns +- 2 ns
python-patched: ..................... 87.6 ns +- 1.6 ns

Mean +- std dev: [python-master] 385 ns +- 2 ns -> [python-patched] 87.6 ns +- 1.6 ns: 4.40x faster (-77%)

(I added Ivan to nosy list because he may implement C version of ABC.)
Date User Action Args
2018-01-13 18:29:30methanesetrecipients: + methane, levkivskyi
2018-01-13 18:29:29methanesetmessageid: <>
2018-01-13 18:29:29methanelinkissue32544 messages
2018-01-13 18:29:29methanecreate