Skip to content

Commit 0143815

Browse files
committed
validate_request and validate_response return value deprecation warning fix
1 parent 35872a9 commit 0143815

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

openapi_core/shortcuts.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from typing import Optional
66
from typing import Union
77

8+
from lazy_object_proxy import Proxy
9+
810
from openapi_core.exceptions import SpecError
911
from openapi_core.finders import SpecClasses
1012
from openapi_core.finders import SpecFinder
@@ -317,19 +319,22 @@ def validate_request(
317319
if cls is None or issubclass(
318320
cls, (RequestUnmarshaller, WebhookRequestUnmarshaller)
319321
):
320-
warnings.warn(
321-
"validate_request is deprecated for unmarshalling data "
322-
"and it will not return any result in the future. "
323-
"Use unmarshal_request function instead.",
324-
DeprecationWarning,
325-
)
326-
return unmarshal_request(
322+
result = unmarshal_request(
327323
request,
328324
spec=spec,
329325
base_url=base_url,
330326
cls=cls,
331327
**validator_kwargs,
332328
)
329+
def return_result() -> RequestUnmarshalResult:
330+
warnings.warn(
331+
"validate_request is deprecated for unmarshalling data "
332+
"and it will not return any result in the future. "
333+
"Use unmarshal_request function instead.",
334+
DeprecationWarning,
335+
)
336+
return result
337+
return Proxy(return_result) # type: ignore
333338
if isinstance(request, WebhookRequest):
334339
if cls is None or issubclass(cls, WebhookRequestValidator):
335340
validate_webhook_request(
@@ -400,20 +405,23 @@ def validate_response(
400405
if cls is None or issubclass(
401406
cls, (ResponseUnmarshaller, WebhookResponseUnmarshaller)
402407
):
403-
warnings.warn(
404-
"validate_response is deprecated for unmarshalling data "
405-
"and it will not return any result in the future. "
406-
"Use unmarshal_response function instead.",
407-
DeprecationWarning,
408-
)
409-
return unmarshal_response(
408+
result = unmarshal_response(
410409
request,
411410
response,
412411
spec=spec,
413412
base_url=base_url,
414413
cls=cls,
415414
**validator_kwargs,
416415
)
416+
def return_result() -> ResponseUnmarshalResult:
417+
warnings.warn(
418+
"validate_response is deprecated for unmarshalling data "
419+
"and it will not return any result in the future. "
420+
"Use unmarshal_response function instead.",
421+
DeprecationWarning,
422+
)
423+
return result
424+
return Proxy(return_result) # type: ignore
417425
if isinstance(request, WebhookRequest):
418426
if cls is None or issubclass(cls, WebhookResponseValidator):
419427
validate_webhook_response(

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ module = [
2727
]
2828
ignore_missing_imports = true
2929

30+
[[tool.mypy.overrides]]
31+
module = "lazy_object_proxy.*"
32+
ignore_missing_imports = true
33+
3034
[tool.poetry]
3135
name = "openapi-core"
3236
version = "0.17.1"
@@ -74,6 +78,7 @@ backports-cached-property = {version = "^1.0.2", python = "<3.8" }
7478
asgiref = "^3.6.0"
7579
jsonschema = "^4.17.3"
7680
multidict = {version = "^6.0.4", optional = true}
81+
lazy-object-proxy = "^1.7.1"
7782

7883
[tool.poetry.extras]
7984
django = ["django"]

0 commit comments

Comments
 (0)