Coding 2022-06-25

By Max Woerner Chase

I did something else today, instead of working on MOTR. As exhibit A against myself, I present, the first cell of the newly created Jupyter notebook, crimes.ipynb:

def base_call(*args, **kwargs):

SENTINEL = object()

class inner:
    def __init__(self, /, sup, default=SENTINEL):
        self.__super = sup
        self.__default = default

    def __getattribute__(self, name):
            return getattr(super().__getattribute__("_inner__super"), name)
        except AttributeError:
            default = super().__getattribute__("_inner__default")
            if default is SENTINEL:
                # Should inject name info
                return base_call
            return default

    def __get__(self, instance, owner):
        old_super = super().__getattribute__("_inner__super")
        new_super = old_super.__get__(instance, owner)
        if new_super is old_super:
            return self
        return inner(new_super)

class BetaMeta(type):
    def mro(cls):
        for base in cls.__bases__:
            assert base is object or isinstance(base, BetaMeta)
        base_mro = super().mro()
        return base_mro[1:-1] + base_mro[:1] + base_mro[-1:]

class Beta(metaclass=BetaMeta):

I'm not sure if this always works, but when I tried it with a basic example, it seemed to work. This code is really brittle. In particular, I kept on having trouble trying to find a way to not need to do inner(super()), which was pretty annoying. Various things not working that kind of seemed like they should have. Oh, well.

Anyway, the goal of all of that nonsense is to allow for BETA-style inheritance. Is that a good idea? Well, with all of that code, there's a way to find out. Once it's cleaned up and gets some proper invocations of the descriptor protocol.

Anyway, I don't want to ponder whether that's "something anybody should have attempted", or whatever, so I'm going to publish this and wind down extra-early.

Good night.