Source code for cake._abc
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import Any, Generic, TypeVar, Iterator
Self = TypeVar('Self')
[docs]class Like(Generic[Self]):
''' Typehint used throughout the cake library,
used to symbolise that a class behaves or can be shown as another implementation.
'''
[docs]class Maybe(Generic[Self]):
''' Typehint used throughout the cake library,
used to hint that an object may derive or be included in another category of objects.
'''
[docs]class Basic(ABC, object):
'''
Represents a basic object which all objects in the cake library derive from,
Using this class we can check if any object belongs to the cake library
'''
[docs]class BasicNode(Basic):
''' Represents an object which can be represented as a node in an expression,
Objects such as shapes and matrices which cannot form an :class:`Expression` object
don't inherit this object.
.. code-block:: py
>>> issubclass(Variable, BasicNode)
True
>>> issubclass(Number, BasicNode)
True
>>> issubclass(Function, BasicNode)
True
'''
[docs]class BasicSolvable(Basic, Maybe[BasicNode]):
''' An object which can be solved via the function ``solve`` '''
[docs] @abstractmethod
def solve(self, **kwds) -> Any:
''' Values for solving the object for a desired value.
.. note::
The parameter format may change for certain objects.
'''
[docs]class BasicEvaluator(Basic, Maybe[BasicNode]):
''' An object which can be evaluated,
like a :class:`BasicSolvable` object except it is abit more then just an expression.
'''
[docs] @abstractmethod
def evaluate(self, **kwds) -> Any:
''' Values for evaluating the object for a desired value.
.. note::
The parameter format may change for certain objects.
'''
[docs]class BasicExpression(Like[Iterator[BasicNode]], BasicSolvable):
''' An object which represents a generic expression. '''
[docs]class BasicVariable(BasicSolvable, Like[BasicExpression]):
''' Represents a variable '''
[docs]class BasicFunction(BasicEvaluator):
''' Represents a mathmatical function '''