(cls, subclass)
Register a virtual subclass of an ABC.
Register a virtual subclass of an ABC.
Register a virtual subclass of an ABC .
def register(cls, subclass):
        """Register a virtual subclass of an ABC."""
        if not isinstance(subclass, (type, types.ClassType)):
            raise TypeError("Can only register classes")
        if issubclass(subclass, cls):
            return  # Already a subclass
        # Subtle: test for cycles *after* testing for "already a subclass";
        # this means we allow X.register(X) and interpret it as a no-op.
        if issubclass(cls, subclass):
            # This would create a cycle, which is bad for the algorithm below
            raise RuntimeError("Refusing to create an inheritance cycle")
        cls._abc_registry.add(subclass)
        ABCMeta._abc_invalidation_counter += 1
def register ( cls , subclass ) : if not isinstance ( subclass , ( type , types . ClassType ) ) : raise TypeError ( "Can only register classes" ) if issubclass ( subclass , cls ) : return # Already a subclass # Subtle: test for cycles *after* testing for "already a subclass"; # this means we allow X.register(X) and interpret it as a no-op. if issubclass ( cls , subclass ) : # This would create a cycle, which is bad for the algorithm below raise RuntimeError ( "Refusing to create an inheritance cycle" ) cls . _abc_registry . add ( subclass ) ABCMeta . _abc_invalidation_counter += 1