There is a type error here when using werkzeug Version 3.1.2 or newer:
from django.conf import settings
from openapi_core import unmarshal_response
from openapi_core.contrib.django import DjangoOpenAPIRequest, DjangoOpenAPIResponse
def test(openapi_request: DjangoOpenAPIRequest, openapi_response: DjangoOpenAPIResponse):
return unmarshal_response(
request=openapi_request,
response=openapi_response, # type error on this line
spec=settings.OPENAPI_SPEC,
)
Since these are no longer compatible, unmarshal_response can no longer accept DjangoOpenAPIResponse as a response parameter without failing typechecking.
Actual Behavior
There is a type error here when using
werkzeug
Version 3.1.2 or newer:Expected Behavior
No type errors in the provided sample code.
Steps to Reproduce
Typecheck the provided sample code using mypy.
OpenAPI Core Version
3.0.0
OpenAPI Core Integration
django
Affected Area(s)
casting, dependencies, unmarshalling
References
Anything else we need to know?
werkzeug
Version 3.1.2 changed the definition ofHeaders
because it isn't technically aMutableMapping
.The
Response
protocol inopenapi_core
here hasMapping[str, Any]
: https://github.com/python-openapi/openapi-core/blob/b8f0644bde3afb4e0273c4cfa8f2ac3eee9f76b3/openapi_core/protocols.py#L122-L123DjangoOpenAPIResponse
has headers typed asHeaders
fromwerkzeug
: https://github.com/python-openapi/openapi-core/blob/b8f0644bde3afb4e0273c4cfa8f2ac3eee9f76b3/openapi_core/contrib/django/responses.py#L33-L35Since these are no longer compatible,
unmarshal_response
can no longer acceptDjangoOpenAPIResponse
as a response parameter without failing typechecking.Would you like to implement a fix?
None