1818import fastapi .utils
1919import pydantic
2020import pydantic ._internal ._decorators
21- import typing_extensions
2221from fastapi import Response
2322from fastapi .dependencies .utils import is_async_gen_callable , is_coroutine_callable , is_gen_callable
2423from fastapi .routing import APIRoute
3736from typing_extensions import (
3837 Any ,
3938 Doc ,
40- NewType ,
4139 Self ,
4240 TypeAlias ,
4341 TypeAliasType ,
@@ -587,9 +585,11 @@ def migrate_route_to_version(self, route: fastapi.routing.APIRoute, *, ignore_re
587585 self ._remake_endpoint_dependencies (route )
588586
589587 def _change_version_of_a_non_container_annotation (self , annotation : Any ) -> Any :
588+ from typing_inspection .typing_objects import is_any , is_newtype , is_typealiastype
589+
590590 if isinstance (annotation , (_BaseGenericAlias , types .GenericAlias )):
591591 return get_origin (annotation )[tuple (self .change_version_of_annotation (arg ) for arg in get_args (annotation ))]
592- elif isinstance (annotation , TypeAliasType ):
592+ elif is_typealiastype (annotation ):
593593 if (
594594 annotation .__module__ is not None and (annotation .__module__ .startswith ("pydantic." ))
595595 ) or annotation .__name__ in _PYDANTIC_ALL_EXPORTED_NAMES :
@@ -616,7 +616,7 @@ def _change_version_of_a_non_container_annotation(self, annotation: Any) -> Any:
616616 return getitem (
617617 tuple (self .change_version_of_annotation (a ) for a in get_args (annotation )),
618618 )
619- elif annotation is typing . Any or annotation is typing_extensions . Any or isinstance (annotation , NewType ):
619+ elif is_any ( annotation ) or is_newtype (annotation ):
620620 return annotation
621621 elif isinstance (annotation , type ):
622622 return self ._change_version_of_type (annotation )
0 commit comments