|
1 | 1 | import abc |
2 | 2 |
|
3 | | -from typing import (Mapping, MutableMapping, List, Union, Iterable, |
4 | | - TypeVar, Tuple, Dict, Optional) |
| 3 | +from collections.abc import Mapping, MutableMapping |
5 | 4 |
|
6 | 5 |
|
7 | | -_T = TypeVar('_T') |
| 6 | +class _TypingMeta(abc.ABCMeta): |
| 7 | + # A fake metaclass to satisfy typing deps in runtime |
| 8 | + # basically MultiMapping[str] and other generic-like type instantiations |
| 9 | + # are emulated. |
| 10 | + # Note: real type hints are provided by __init__.pyi stub file |
| 11 | + def __getitem__(self, key): |
| 12 | + return self |
8 | 13 |
|
9 | | -_D = TypeVar('_D') |
10 | 14 |
|
11 | | - |
12 | | -# Note: type defs are slightly different from __init__.pyi version The |
13 | | -# correct one (and checked by mypy) is the later. Type checks here |
14 | | -# exists for sake of consistency and allowing to instantiate |
15 | | -# MultiMapiing[_T] in inline python code |
16 | | - |
17 | | - |
18 | | -class MultiMapping(Mapping[str, _T]): |
| 15 | +class MultiMapping(Mapping, metaclass=_TypingMeta): |
19 | 16 |
|
20 | 17 | @abc.abstractmethod |
21 | | - def getall(self, key: str, |
22 | | - default: Optional[_D]=None) -> Union[List[_T], _D, None]: |
| 18 | + def getall(self, key, default=None): |
23 | 19 | raise KeyError |
24 | 20 |
|
25 | 21 | @abc.abstractmethod |
26 | | - def getone(self, key: str, |
27 | | - default: Optional[_D]=None) -> Union[_T, _D, None]: |
| 22 | + def getone(self, key, default=None): |
28 | 23 | raise KeyError |
29 | 24 |
|
30 | 25 |
|
31 | | -_Arg = Union[Mapping[str, _T], |
32 | | - Dict[str, _T], |
33 | | - MultiMapping[_T], |
34 | | - Iterable[Tuple[str, _T]]] |
35 | | - |
36 | | - |
37 | | -class MutableMultiMapping(MultiMapping[_T], MutableMapping[str, _T]): |
| 26 | +class MutableMultiMapping(MultiMapping, MutableMapping): |
38 | 27 |
|
39 | 28 | @abc.abstractmethod |
40 | | - def add(self, key: str, value: _T) -> None: |
| 29 | + def add(self, key, value): |
41 | 30 | raise NotImplementedError |
42 | 31 |
|
43 | 32 | @abc.abstractmethod |
44 | | - def extend(self, *args: _Arg[_T], **kwargs: _T) -> None: |
| 33 | + def extend(self, *args, **kwargs): |
45 | 34 | raise NotImplementedError |
46 | 35 |
|
47 | 36 | @abc.abstractmethod |
48 | | - def popone(self, key: str, default: Optional[_T]=None) -> _T: |
| 37 | + def popone(self, key, default=None): |
49 | 38 | raise KeyError |
50 | 39 |
|
51 | 40 | @abc.abstractmethod |
52 | | - def popall(self, key: str, default: Optional[_T]=None) -> List[_T]: |
| 41 | + def popall(self, key, default=None): |
53 | 42 | raise KeyError |
0 commit comments