Skip to content

Prevent instantiation of abstract base classes #82

@goerz

Description

@goerz

Python prevents instantiation of abstract base classes, but only if they have abstract methods. Thus, for example, the following works:

>>> QuantumSymbol('a', hs=1)

despite QuantumSymbol being an abstract class:

class QuantumSymbol(QuantumExpression, metaclass=ABCMeta)

This can cause problems, as abstract classes may not define all the necessary class attributes for algebraic operations to work (and there's no way in Python to declare abstract class attributes, which Python could catch similar to abstract methods)

We should figure out some general way in Expression.__init__ to raise an exception if any class whose type is a direct subclass of ABCMeta is being instantiated. So far, I haven't found a way to perform this check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions