Skip to content

Commit 5016202

Browse files
committed
fix: fix typing for older versions of python
1 parent f6df2fd commit 5016202

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

elasticsearch_dsl/query.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,18 @@
1818
import collections.abc
1919
from copy import deepcopy
2020
from itertools import chain
21-
from typing import Any, Callable, ClassVar, Optional, Protocol, TypeVar, Union, overload
21+
from typing import (
22+
Any,
23+
Callable,
24+
ClassVar,
25+
Mapping,
26+
MutableMapping,
27+
Optional,
28+
Protocol,
29+
TypeVar,
30+
Union,
31+
overload,
32+
)
2233

2334
# 'SF' looks unused but the test suite assumes it's available
2435
# from this module so others are liable to do so as well.
@@ -27,15 +38,15 @@
2738
from .utils import DslBase
2839

2940
_T = TypeVar("_T")
30-
_M = TypeVar("_M", bound=collections.abc.Mapping[str, Any])
41+
_M = TypeVar("_M", bound=Mapping[str, Any])
3142

3243

3344
class QProxiedProtocol(Protocol[_T]):
3445
_proxied: _T
3546

3647

3748
@overload
38-
def Q(name_or_query: collections.abc.MutableMapping[str, _M]) -> "Query": ...
49+
def Q(name_or_query: MutableMapping[str, _M]) -> "Query": ...
3950

4051

4152
@overload
@@ -55,7 +66,7 @@ def Q(
5566
str,
5667
"Query",
5768
QProxiedProtocol[_T],
58-
collections.abc.MutableMapping[str, _M],
69+
MutableMapping[str, _M],
5970
] = "match_all",
6071
**params: Any,
6172
) -> Union["Query", _T]:

elasticsearch_dsl/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
import collections.abc
2020
from copy import copy
21-
from typing import Any, Optional, Self
21+
from typing import Any, Optional, Type
22+
23+
from typing_extensions import Self
2224

2325
from .exceptions import UnknownDslObject, ValidationException
2426

@@ -253,8 +255,8 @@ class DslBase(metaclass=DslMeta):
253255

254256
@classmethod
255257
def get_dsl_class(
256-
cls: type[Self], name: str, default: Optional[str] = None
257-
) -> type[Self]:
258+
cls: Type[Self], name: str, default: Optional[str] = None
259+
) -> Type[Self]:
258260
try:
259261
return cls._classes[name]
260262
except KeyError:

0 commit comments

Comments
 (0)