diff options
Diffstat (limited to '')
-rw-r--r-- | share/extensions/inkex/interfaces/IElement.py | 39 | ||||
-rw-r--r-- | share/extensions/inkex/interfaces/__init__.py | 0 |
2 files changed, 39 insertions, 0 deletions
diff --git a/share/extensions/inkex/interfaces/IElement.py b/share/extensions/inkex/interfaces/IElement.py new file mode 100644 index 0000000..3e9df53 --- /dev/null +++ b/share/extensions/inkex/interfaces/IElement.py @@ -0,0 +1,39 @@ +"""Element abstractions for type comparisons without circular imports + +.. versionadded:: 1.2""" + +from __future__ import annotations + +from abc import ABC, abstractmethod + +import sys +from lxml import etree + +if sys.version_info >= (3, 8): + from typing import Protocol +else: + from typing_extensions import Protocol + + +class IBaseElement(ABC, etree.ElementBase): + """Abstraction for BaseElement to avoid circular imports""" + + @abstractmethod + def get_id(self, as_url=0): + """Returns the element ID. If not set, generates a unique ID.""" + raise NotImplementedError + + +class BaseElementProtocol(Protocol): + """Abstraction for BaseElement, to be used as typehint in mixin classes""" + + def get_id(self, as_url=0) -> str: + """Returns the element ID. If not set, generates a unique ID.""" + + @property + def root(self) -> ISVGDocumentElement: + """Returns the element's root.""" + + +class ISVGDocumentElement(IBaseElement): + """Abstraction for SVGDocumentElement""" diff --git a/share/extensions/inkex/interfaces/__init__.py b/share/extensions/inkex/interfaces/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/share/extensions/inkex/interfaces/__init__.py |