[issue1762] Inheriting from ABC slows Decimal down.

Christian Heimes report at bugs.python.org
Tue Jan 8 18:02:05 CET 2008


Christian Heimes added the comment:

__instancecheck__ contains unnecessary code. If we restrict ABCs to new
style classes we could make the function faster:

Old:

    def __instancecheck__(cls, instance):
        """Override for isinstance(instance, cls)."""
        return any(cls.__subclasscheck__(c)
                   for c in {instance.__class__, type(instance)})
New:

    def __instancecheck__(cls, instance):
        """Override for isinstance(instance, cls)."""
        # safe a function call for common case
        if instance.__class__ in cls._abc_cache:
            return True
        return cls.__subclasscheck__(instance.__class__)

----------
assignee:  -> gvanrossum
nosy: +gvanrossum

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1762>
__________________________________


More information about the Python-bugs-list mailing list