Skip to content

Commit b434f18

Browse files
authored
Drop Python 3.7 (#178)
1 parent 887c3d1 commit b434f18

File tree

10 files changed

+20
-35
lines changed

10 files changed

+20
-35
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
strategy:
4141
fail-fast: false
4242
matrix:
43-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
43+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
4444
os: ["ubuntu-latest"]
4545
experimental: [false]
4646
nox-session: ['']

elastic_transport/_compat.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424

2525
string_types = (str, bytes)
2626

27-
if sys.version_info >= (3, 7): # dict is insert ordered on Python 3.7+
28-
ordered_dict = dict
29-
else:
30-
from collections import OrderedDict as ordered_dict
31-
32-
3327
T = TypeVar("T")
3428

3529

@@ -107,7 +101,6 @@ def warn_stacklevel() -> int:
107101

108102
__all__ = [
109103
"await_if_coro",
110-
"ordered_dict",
111104
"quote",
112105
"urlparse",
113106
"urlencode",

elastic_transport/_models.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
)
3838

3939
if TYPE_CHECKING:
40-
from typing_extensions import Final
40+
from typing import Final
4141

4242

4343
class DefaultType(enum.Enum):
@@ -59,12 +59,7 @@ def __str__(self) -> str:
5959

6060
T = TypeVar("T")
6161

62-
try:
63-
from ssl import TLSVersion
64-
65-
_TYPE_SSL_VERSION = Union[int, TLSVersion]
66-
except ImportError:
67-
_TYPE_SSL_VERSION = int # type: ignore[misc]
62+
_TYPE_SSL_VERSION = Union[int, ssl.TLSVersion]
6863

6964

7065
class HttpHeaders(MutableMapping[str, str]):
@@ -278,7 +273,7 @@ class NodeConfig:
278273
#: **experimental**.
279274
ssl_assert_fingerprint: Optional[str] = None
280275
#: Minimum TLS version to use to connect to the node. Can be either
281-
#: :class:`ssl.TLSVersion` on Python 3.7+ or one of the
276+
#: :class:`ssl.TLSVersion` or one of the deprecated
282277
#: ``ssl.PROTOCOL_TLSvX`` instances.
283278
ssl_version: Optional[_TYPE_SSL_VERSION] = None
284279
#: Pre-configured :class:`ssl.SSLContext` object. If this value

elastic_transport/_node/_http_httpx.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import ssl
2121
import time
2222
import warnings
23-
from typing import Optional, Union
23+
from typing import Literal, Optional, Union
2424

2525
from .._compat import warn_stacklevel
2626
from .._exceptions import ConnectionError, ConnectionTimeout, SecurityWarning, TlsError
@@ -58,8 +58,7 @@ def __init__(self, config: NodeConfig):
5858
"httpx does not support certificate pinning. https://github.com/encode/httpx/issues/761"
5959
)
6060

61-
# TODO switch to Literal[False] when dropping Python 3.7 support
62-
ssl_context: Union[ssl.SSLContext, bool] = False
61+
ssl_context: Union[ssl.SSLContext, Literal[False]] = False
6362
if config.scheme == "https":
6463
if config.ssl_context is not None:
6564
ssl_context = ssl_context_from_node_config(config)

elastic_transport/_node_pool.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
overload,
3535
)
3636

37-
from ._compat import Lock, ordered_dict
37+
from ._compat import Lock
3838
from ._models import NodeConfig
3939
from ._node import BaseNode
4040

@@ -182,8 +182,8 @@ def __init__(
182182
self._node_class = node_class
183183
self._node_selector = node_selector_class(node_configs)
184184

185-
# Maintain insert order
186-
self._all_nodes: Dict[NodeConfig, BaseNode] = ordered_dict()
185+
# _all_nodes relies on dict insert order
186+
self._all_nodes: Dict[NodeConfig, BaseNode] = {}
187187
for node_config in node_configs:
188188
self._all_nodes[node_config] = self._node_class(node_config)
189189

@@ -196,11 +196,11 @@ def __init__(
196196

197197
# Collection of currently-alive nodes. This is an ordered
198198
# dict so round-robin actually works.
199-
self._alive_nodes: Dict[NodeConfig, BaseNode] = ordered_dict(self._all_nodes)
199+
self._alive_nodes: Dict[NodeConfig, BaseNode] = dict(self._all_nodes)
200200

201201
# PriorityQueue for thread safety and ease of timeout management
202202
self._dead_nodes: PriorityQueue[Tuple[float, BaseNode]] = PriorityQueue()
203-
self._dead_consecutive_failures: Dict[NodeConfig, int] = defaultdict(lambda: 0)
203+
self._dead_consecutive_failures: Dict[NodeConfig, int] = defaultdict(int)
204204

205205
# Nodes that have been marked as 'removed' to be thread-safe.
206206
self._removed_nodes: Set[NodeConfig] = set()

elastic_transport/_otel.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717

1818
from __future__ import annotations
1919

20-
from typing import TYPE_CHECKING, Mapping
20+
from typing import TYPE_CHECKING, Literal, Mapping
2121

2222
if TYPE_CHECKING:
23-
from typing import Literal
24-
2523
from opentelemetry.trace import Span
2624

2725

@@ -45,8 +43,7 @@ def __init__(
4543
self,
4644
otel_span: Span | None,
4745
endpoint_id: str | None = None,
48-
# TODO import Literal at the top-level when dropping Python 3.7
49-
body_strategy: 'Literal["omit", "raw"]' = "omit",
46+
body_strategy: Literal["omit", "raw"] = "omit",
5047
):
5148
self.otel_span = otel_span
5249
self.body_strategy = body_strategy

elastic_transport/client_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ def basic_auth_to_header(basic_auth: Tuple[str, str]) -> str:
179179
raise ValueError(
180180
"'basic_auth' must be a 2-tuple of str/bytes (username, password)"
181181
)
182-
return f"Basic {base64.b64encode((b':'.join(to_bytes(x) for x in basic_auth))).decode()}"
182+
return (
183+
f"Basic {base64.b64encode(b':'.join(to_bytes(x) for x in basic_auth)).decode()}"
184+
)
183185

184186

185187
def url_to_node_config(

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def lint(session):
5959
session.run("mypy", "--strict", "--show-error-codes", "elastic_transport/")
6060

6161

62-
@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"])
62+
@nox.session(python=["3.8", "3.9", "3.10", "3.11", "3.12"])
6363
def test(session):
6464
session.install(".[develop]")
6565
session.run(

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"certifi",
5555
"importlib-metadata; python_version<'3.8'",
5656
],
57-
python_requires=">=3.7",
57+
python_requires=">=3.8",
5858
extras_require={
5959
"develop": [
6060
"pytest",
@@ -83,7 +83,6 @@
8383
"Operating System :: OS Independent",
8484
"Programming Language :: Python",
8585
"Programming Language :: Python :: 3",
86-
"Programming Language :: Python :: 3.7",
8786
"Programming Language :: Python :: 3.8",
8887
"Programming Language :: Python :: 3.9",
8988
"Programming Language :: Python :: 3.10",

utils/license-headers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def find_files_to_fix(sources: List[str]) -> Iterator[str]:
6565
def does_file_need_fix(filepath: str) -> bool:
6666
if not filepath.endswith(".py"):
6767
return False
68-
with open(filepath, mode="r") as f:
68+
with open(filepath) as f:
6969
first_license_line = None
7070
for line in f:
7171
if line == license_header_lines[0]:
@@ -82,7 +82,7 @@ def does_file_need_fix(filepath: str) -> bool:
8282

8383

8484
def add_header_to_file(filepath: str) -> None:
85-
with open(filepath, mode="r") as f:
85+
with open(filepath) as f:
8686
lines = list(f)
8787
i = 0
8888
for i, line in enumerate(lines):

0 commit comments

Comments
 (0)