Skip to content

Commit

Permalink
Drop Python 3.7 (#178)
Browse files Browse the repository at this point in the history
(cherry picked from commit b434f18)
  • Loading branch information
pquentin authored and github-actions[bot] committed Jul 31, 2024
1 parent f72f0ae commit 7a024a7
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: ["ubuntu-latest"]
experimental: [false]
nox-session: ['']
Expand Down
7 changes: 0 additions & 7 deletions elastic_transport/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@

string_types = (str, bytes)

if sys.version_info >= (3, 7): # dict is insert ordered on Python 3.7+
ordered_dict = dict
else:
from collections import OrderedDict as ordered_dict


T = TypeVar("T")


Expand Down Expand Up @@ -107,7 +101,6 @@ def warn_stacklevel() -> int:

__all__ = [
"await_if_coro",
"ordered_dict",
"quote",
"urlparse",
"urlencode",
Expand Down
11 changes: 3 additions & 8 deletions elastic_transport/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
)

if TYPE_CHECKING:
from typing_extensions import Final
from typing import Final


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

T = TypeVar("T")

try:
from ssl import TLSVersion

_TYPE_SSL_VERSION = Union[int, TLSVersion]
except ImportError:
_TYPE_SSL_VERSION = int # type: ignore[misc]
_TYPE_SSL_VERSION = Union[int, ssl.TLSVersion]


class HttpHeaders(MutableMapping[str, str]):
Expand Down Expand Up @@ -278,7 +273,7 @@ class NodeConfig:
#: **experimental**.
ssl_assert_fingerprint: Optional[str] = None
#: Minimum TLS version to use to connect to the node. Can be either
#: :class:`ssl.TLSVersion` on Python 3.7+ or one of the
#: :class:`ssl.TLSVersion` or one of the deprecated
#: ``ssl.PROTOCOL_TLSvX`` instances.
ssl_version: Optional[_TYPE_SSL_VERSION] = None
#: Pre-configured :class:`ssl.SSLContext` object. If this value
Expand Down
5 changes: 2 additions & 3 deletions elastic_transport/_node/_http_httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import ssl
import time
import warnings
from typing import Optional, Union
from typing import Literal, Optional, Union

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

# TODO switch to Literal[False] when dropping Python 3.7 support
ssl_context: Union[ssl.SSLContext, bool] = False
ssl_context: Union[ssl.SSLContext, Literal[False]] = False
if config.scheme == "https":
if config.ssl_context is not None:
ssl_context = ssl_context_from_node_config(config)
Expand Down
10 changes: 5 additions & 5 deletions elastic_transport/_node_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
overload,
)

from ._compat import Lock, ordered_dict
from ._compat import Lock
from ._models import NodeConfig
from ._node import BaseNode

Expand Down Expand Up @@ -182,8 +182,8 @@ def __init__(
self._node_class = node_class
self._node_selector = node_selector_class(node_configs)

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

Expand All @@ -196,11 +196,11 @@ def __init__(

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

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

# Nodes that have been marked as 'removed' to be thread-safe.
self._removed_nodes: Set[NodeConfig] = set()
Expand Down
7 changes: 2 additions & 5 deletions elastic_transport/_otel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Mapping
from typing import TYPE_CHECKING, Literal, Mapping

if TYPE_CHECKING:
from typing import Literal

from opentelemetry.trace import Span


Expand All @@ -45,8 +43,7 @@ def __init__(
self,
otel_span: Span | None,
endpoint_id: str | None = None,
# TODO import Literal at the top-level when dropping Python 3.7
body_strategy: 'Literal["omit", "raw"]' = "omit",
body_strategy: Literal["omit", "raw"] = "omit",
):
self.otel_span = otel_span
self.body_strategy = body_strategy
Expand Down
4 changes: 3 additions & 1 deletion elastic_transport/client_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ def basic_auth_to_header(basic_auth: Tuple[str, str]) -> str:
raise ValueError(
"'basic_auth' must be a 2-tuple of str/bytes (username, password)"
)
return f"Basic {base64.b64encode((b':'.join(to_bytes(x) for x in basic_auth))).decode()}"
return (
f"Basic {base64.b64encode(b':'.join(to_bytes(x) for x in basic_auth)).decode()}"
)


def url_to_node_config(
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def lint(session):
session.run("mypy", "--strict", "--show-error-codes", "elastic_transport/")


@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"])
@nox.session(python=["3.8", "3.9", "3.10", "3.11", "3.12"])
def test(session):
session.install(".[develop]")
session.run(
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"certifi",
"importlib-metadata; python_version<'3.8'",
],
python_requires=">=3.7",
python_requires=">=3.8",
extras_require={
"develop": [
"pytest",
Expand Down Expand Up @@ -83,7 +83,6 @@
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand Down
4 changes: 2 additions & 2 deletions utils/license-headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def find_files_to_fix(sources: List[str]) -> Iterator[str]:
def does_file_need_fix(filepath: str) -> bool:
if not filepath.endswith(".py"):
return False
with open(filepath, mode="r") as f:
with open(filepath) as f:
first_license_line = None
for line in f:
if line == license_header_lines[0]:
Expand All @@ -82,7 +82,7 @@ def does_file_need_fix(filepath: str) -> bool:


def add_header_to_file(filepath: str) -> None:
with open(filepath, mode="r") as f:
with open(filepath) as f:
lines = list(f)
i = 0
for i, line in enumerate(lines):
Expand Down

0 comments on commit 7a024a7

Please sign in to comment.