spyder.api.utils#

API utilities.

Functions

abstract_attribute([obj])

Decorator to mark abstract attributes.

get_class_values(cls)

Get the attribute values for the class enumerations used in our API.

Classes

ABCMeta(name, bases, namespace, /, **kwargs)

Metaclass to mark abstract classes.

DummyAttribute()

Dummy class to mark abstract attributes.

PrefixNode([path])

Utility class used to represent a prefixed string tuple.

PrefixedTuple([path])

Utility class to store and iterate over prefixed string tuples.

classproperty([fget, fset, fdel, doc])

Decorator to declare class constants as properties that require additional computation.

spyder.api.utils.get_class_values(cls)[source]#

Get the attribute values for the class enumerations used in our API.

Idea from: https://stackoverflow.com/a/17249228/438386

class spyder.api.utils.PrefixNode(path=None)[source]#

Bases: object

Utility class used to represent a prefixed string tuple.

class spyder.api.utils.PrefixedTuple(path=None)[source]#

Bases: PrefixNode

Utility class to store and iterate over prefixed string tuples.

class spyder.api.utils.classproperty(fget=None, fset=None, fdel=None, doc=None)[source]#

Bases: property

Decorator to declare class constants as properties that require additional computation.

Taken from: https://stackoverflow.com/a/7864317/438386

class spyder.api.utils.DummyAttribute[source]#

Bases: object

Dummy class to mark abstract attributes.

spyder.api.utils.abstract_attribute(obj: Callable[[_P], _T] | DummyAttribute | None = None) _T[source]#

Decorator to mark abstract attributes. Must be used in conjunction with the ABCMeta metaclass.

class spyder.api.utils.ABCMeta(name, bases, namespace, /, **kwargs)[source]#

Bases: ABCMeta

Metaclass to mark abstract classes.

Adds support for abstract attributes. If a class has abstract attributes and is instantiated, a NotImplementedError is raised.

Usage#

class MyABC(metaclass=ABCMeta):
    @abstract_attribute
    def my_abstract_attribute(self):
        pass

class MyClassOK(MyABC):
    def __init__(self):
        self.my_abstract_attribute = 1

class MyClassNotOK(MyABC):
    pass
raises NotImplementedError:

When it’s not possible to instantiate an abstract class with abstract attributes.