spyder.api.utils#
Helper functions to work with the Spyder plugin API.
Functions
|
Decorator to mark abstract attributes. |
|
Get the attribute values for the class enumerations used in our API. |
Classes
|
Metaclass to mark abstract classes. |
Dummy class to mark abstract attributes. |
|
|
Utility class used to represent a prefixed string tuple. |
|
Utility class to store and iterate over prefixed string tuples. |
|
Decorator to declare class constants requiring computation as properties. |
- spyder.api.utils.get_class_values(cls) list[str][source]#
Get the attribute values for the class enumerations used in our API.
Idea from Stack Overflow.
- class spyder.api.utils.PrefixNode(path: tuple[str, ...] | None = None)[source]#
Bases:
objectUtility class used to represent a prefixed string tuple.
- class spyder.api.utils.PrefixedTuple(path: tuple[str, ...] | None = None)[source]#
Bases:
PrefixNodeUtility class to store and iterate over prefixed string tuples.
- class spyder.api.utils.classproperty(fget=None, fset=None, fdel=None, doc=None)[source]#
Bases:
propertyDecorator to declare class constants requiring computation as properties.
Idea from Stack Overflow.
- class spyder.api.utils.DummyAttribute[source]#
Bases:
objectDummy 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
abc.ABCMetametaclass.- Parameters:
obj (collections.abc.Callable[_P, _T] | DummyAttribute | None, optional) – The callable attribute to mark as abstract, a new instance of
DummyAttributeby default.- Returns:
The result of executing the callable attribute
obj.- Return type:
_T
- class spyder.api.utils.ABCMeta(name, bases, namespace, /, **kwargs)[source]#
Bases:
ABCMetaMetaclass 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.