Skip to content

Commit 37b027c

Browse files
committed
Deprecate non-async ResponseParser.parse methods
To avoid a breaking change the callers of a ResponseParser.parse method yield a deprecation warning when a non-async method is found.
1 parent b490745 commit 37b027c

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

CHANGES.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Changes
55
^^^^^^^^^^^^^^^^^^^
66
* patch `ResponseParser`
77
* use SPDX license identifier for project metadata
8-
* refactor `AioResponseParser` to have a consistent async implementation of the `parse` method.
8+
* refactor ``AioResponseParser`` to have a consistent async implementation of the `parse` method.
9+
sync `parse` methods are deprecated and will be removed in a future release.``
910

1011
2.21.1 (2025-03-04)
1112
^^^^^^^^^^^^^^^^^^^

aiobotocore/endpoint.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import asyncio
2+
import inspect
3+
import warnings
24

35
from botocore.endpoint import (
46
DEFAULT_TIMEOUT,
@@ -204,9 +206,15 @@ async def _do_get_response(self, request, operation_model, context):
204206
)
205207
parser = self._response_parser_factory.create_parser(protocol)
206208

207-
parsed_response = await parser.parse(
209+
parsed_response = parser.parse(
208210
response_dict, operation_model.output_shape
209211
)
212+
if inspect.isawaitable(parsed_response):
213+
parsed_response = await parsed_response
214+
else:
215+
warnings.deprecated(
216+
f"The use of non-async `parse` function on {parser.__class__.__name__} is deprecated."
217+
)
210218
parsed_response.update(customized_response_dict)
211219

212220
if http_response.status_code >= 300:
@@ -234,7 +242,13 @@ async def _add_modeled_error_fields(
234242
if error_shape is None:
235243
return
236244

237-
modeled_parse = await parser.parse(response_dict, error_shape)
245+
modeled_parse = parser.parse(response_dict, error_shape)
246+
if inspect.isawaitable(modeled_parse):
247+
modeled_parse = await modeled_parse
248+
else:
249+
warnings.deprecated(
250+
f"The use of non-async `parse` function on {parser.__class__.__name__} is deprecated."
251+
)
238252
# TODO: avoid naming conflicts with ResponseMetadata and Error
239253
parsed_response.update(modeled_parse)
240254

0 commit comments

Comments
 (0)