Skip to content

Add support for metaclasses other than type #65

@amtriathlon

Description

@amtriathlon

According to http://www.python.org/dev/peps/pep-3115/ the way to specify a metaclass other than type is to use the keyword-only argument metaclass in the class statement:

class Foo(base1, base2, metaclass=mymeta):
         ...

the metaclass is called with name, bases and dict plus any additional keyword argument in the class statement to effectively create the class object.

The metaclass can also define the "dict" used for class attributes if it has a prepare method with is called as follows:

   def prepare_class(name, *bases, metaclass=None, **kwargs):
          if metaclass is None:
             metaclass = compute_default_metaclass(bases)
          prepare = getattr(metaclass, '__prepare__', None)
          if prepare is not None:
             return prepare(name, bases, **kwargs)
          else:
             return dict()

The modifications seems not very difficult, but the major problem seems to be an incompatibility with our class desugar strategy since the class body integrity is lost in the process.

Update: the class body integrity issue was solved in 8d00257

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions