Skip to content

Commit 2a425af

Browse files
committed
#270 Fix invalid typing checks that didn't take typing/typing_extensions differences into account
1 parent ca3f3a1 commit 2a425af

File tree

5 files changed

+252
-250
lines changed

5 files changed

+252
-250
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
default_language_version:
2-
python: python3.10
2+
python: python3
33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
55
rev: v5.0.0

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ Please follow [the Keep a Changelog standard](https://keepachangelog.com/en/1.0.
55

66
## [Unreleased]
77

8+
### Added
9+
10+
- `typing_inspection` dependency from pydantic team for complex isinstance checks that must be the same between `typing` and `typing_extensions`
11+
12+
813
## [5.3.3]
914

1015
### Fixed

cadwyn/schema_generation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import fastapi.utils
1919
import pydantic
2020
import pydantic._internal._decorators
21-
import typing_extensions
2221
from fastapi import Response
2322
from fastapi.dependencies.utils import is_async_gen_callable, is_coroutine_callable, is_gen_callable
2423
from fastapi.routing import APIRoute
@@ -37,7 +36,6 @@
3736
from 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)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ dependencies = [
5757
"jinja2 >=3.1.2",
5858
"backports-strenum >=1.3.1,<2; python_version < '3.11'",
5959
"typing-extensions>=4.8.0",
60+
"typing-inspection>=0.4.0",
6061
]
6162

6263

0 commit comments

Comments
 (0)