From 9ce01c744665ea9c633b71c922e63db7a23e33f5 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Mon, 31 Mar 2025 16:10:39 +0100 Subject: [PATCH] Remove unneded nonlocal and global declarations (#2866) (cherry picked from commit 83025a601ce112e6045abe1b5d84cfbaed722b3f) --- elasticsearch/_async/client/_base.py | 1 - elasticsearch/_async/helpers.py | 1 - elasticsearch/_sync/client/_base.py | 1 - elasticsearch/_sync/client/utils.py | 3 --- test_elasticsearch/test_server/test_rest_api_spec.py | 4 +--- utils/build-dists.py | 1 - 6 files changed, 1 insertion(+), 10 deletions(-) diff --git a/elasticsearch/_async/client/_base.py b/elasticsearch/_async/client/_base.py index dd0b0f44e..cc090671c 100644 --- a/elasticsearch/_async/client/_base.py +++ b/elasticsearch/_async/client/_base.py @@ -298,7 +298,6 @@ async def _perform_request( def mimetype_header_to_compat(header: str) -> None: # Converts all parts of a Accept/Content-Type headers # from application/X -> application/vnd.elasticsearch+X - nonlocal request_headers mimetype = request_headers.get(header, None) if mimetype: request_headers[header] = _COMPAT_MIMETYPE_RE.sub( diff --git a/elasticsearch/_async/helpers.py b/elasticsearch/_async/helpers.py index 4c53f0bbe..e4d5e6bc5 100644 --- a/elasticsearch/_async/helpers.py +++ b/elasticsearch/_async/helpers.py @@ -136,7 +136,6 @@ def aiter(x: Union[Iterable[T], AsyncIterable[T]]) -> AsyncIterator[T]: return x.__aiter__() async def f() -> AsyncIterable[T]: - nonlocal x ix: Iterable[T] = x for item in ix: yield item diff --git a/elasticsearch/_sync/client/_base.py b/elasticsearch/_sync/client/_base.py index 8929b1db7..868b71073 100644 --- a/elasticsearch/_sync/client/_base.py +++ b/elasticsearch/_sync/client/_base.py @@ -298,7 +298,6 @@ def _perform_request( def mimetype_header_to_compat(header: str) -> None: # Converts all parts of a Accept/Content-Type headers # from application/X -> application/vnd.elasticsearch+X - nonlocal request_headers mimetype = request_headers.get(header, None) if mimetype: request_headers[header] = _COMPAT_MIMETYPE_RE.sub( diff --git a/elasticsearch/_sync/client/utils.py b/elasticsearch/_sync/client/utils.py index 9f957987c..51afe1c78 100644 --- a/elasticsearch/_sync/client/utils.py +++ b/elasticsearch/_sync/client/utils.py @@ -134,7 +134,6 @@ def client_node_configs( def apply_node_options(node_config: NodeConfig) -> NodeConfig: """Needs special handling of headers since .replace() wipes out existing headers""" - nonlocal node_options headers = node_config.headers.copy() # type: ignore[attr-defined] headers_to_add = node_options.pop("headers", ()) @@ -343,8 +342,6 @@ def _rewrite_parameters( def wrapper(api: F) -> F: @wraps(api) def wrapped(*args: Any, **kwargs: Any) -> Any: - nonlocal api, body_name, body_fields - # Let's give a nicer error message when users pass positional arguments. if len(args) >= 2: raise TypeError( diff --git a/test_elasticsearch/test_server/test_rest_api_spec.py b/test_elasticsearch/test_server/test_rest_api_spec.py index 0b602684a..a84f0822a 100644 --- a/test_elasticsearch/test_server/test_rest_api_spec.py +++ b/test_elasticsearch/test_server/test_rest_api_spec.py @@ -280,8 +280,6 @@ def run_catch(self, catch, exception): self.last_response = exception.body def run_skip(self, skip): - global IMPLEMENTED_FEATURES - if "features" in skip: features = skip["features"] if not isinstance(features, (tuple, list)): @@ -437,7 +435,7 @@ def _lookup(self, path): return value def _feature_enabled(self, name): - global XPACK_FEATURES, IMPLEMENTED_FEATURES + global XPACK_FEATURES if XPACK_FEATURES is None: try: xinfo = self.client.xpack.info() diff --git a/utils/build-dists.py b/utils/build-dists.py index ec8083103..d67d6053a 100644 --- a/utils/build-dists.py +++ b/utils/build-dists.py @@ -42,7 +42,6 @@ def set_tmp_dir(): def run(*argv, expect_exit_code=0): - global tmp_dir try: prev_dir = os.getcwd() if tmp_dir is None: