1 34
import abc
2 34
from collections.abc import Mapping, MutableMapping
3

4

5 34
class _TypingMeta(abc.ABCMeta):
6
    # A fake metaclass to satisfy typing deps in runtime
7
    # basically MultiMapping[str] and other generic-like type instantiations
8
    # are emulated.
9
    # Note: real type hints are provided by __init__.pyi stub file
10 34
    def __getitem__(self, key):
11 34
        return self
12

13

14 34
class MultiMapping(Mapping, metaclass=_TypingMeta):
15 34
    @abc.abstractmethod
16 34
    def getall(self, key, default=None):
17 34
        raise KeyError
18

19 34
    @abc.abstractmethod
20 34
    def getone(self, key, default=None):
21 34
        raise KeyError
22

23

24 34
class MutableMultiMapping(MultiMapping, MutableMapping):
25 34
    @abc.abstractmethod
26 16
    def add(self, key, value):
27 34
        raise NotImplementedError
28

29 34
    @abc.abstractmethod
30 16
    def extend(self, *args, **kwargs):
31 34
        raise NotImplementedError
32

33 34
    @abc.abstractmethod
34 34
    def popone(self, key, default=None):
35 34
        raise KeyError
36

37 34
    @abc.abstractmethod
38 34
    def popall(self, key, default=None):
39 34
        raise KeyError

Read our documentation on viewing source code .

Loading