summaryrefslogtreecommitdiffstats
path: root/share/extensions/inkex/interfaces/IElement.py
blob: 3e9df53a5c70a36f471c9da1071c6d52a4bd732c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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"""