strawberry-graphql 0.259.1__py3-none-any.whl → 0.260.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- strawberry/utils/inspect.py +50 -38
- {strawberry_graphql-0.259.1.dist-info → strawberry_graphql-0.260.0.dist-info}/METADATA +1 -1
- {strawberry_graphql-0.259.1.dist-info → strawberry_graphql-0.260.0.dist-info}/RECORD +6 -6
- {strawberry_graphql-0.259.1.dist-info → strawberry_graphql-0.260.0.dist-info}/LICENSE +0 -0
- {strawberry_graphql-0.259.1.dist-info → strawberry_graphql-0.260.0.dist-info}/WHEEL +0 -0
- {strawberry_graphql-0.259.1.dist-info → strawberry_graphql-0.260.0.dist-info}/entry_points.txt +0 -0
strawberry/utils/inspect.py
CHANGED
@@ -4,13 +4,16 @@ from functools import lru_cache
|
|
4
4
|
from typing import (
|
5
5
|
Any,
|
6
6
|
Callable,
|
7
|
+
Generic,
|
7
8
|
Optional,
|
9
|
+
Protocol,
|
8
10
|
TypeVar,
|
11
|
+
Union,
|
12
|
+
get_args,
|
9
13
|
get_origin,
|
10
14
|
)
|
11
|
-
from typing_extensions import get_args
|
12
15
|
|
13
|
-
|
16
|
+
import strawberry
|
14
17
|
|
15
18
|
|
16
19
|
def in_async_context() -> bool:
|
@@ -67,13 +70,13 @@ def get_specialized_type_var_map(cls: type) -> Optional[dict[str, type]]:
|
|
67
70
|
# {}
|
68
71
|
|
69
72
|
get_specialized_type_var_map(Bar)
|
70
|
-
# {
|
73
|
+
# {}
|
71
74
|
|
72
75
|
get_specialized_type_var_map(IntBar)
|
73
|
-
# {~T: int}
|
76
|
+
# {~T: int, ~K: int}
|
74
77
|
|
75
78
|
get_specialized_type_var_map(IntBarSubclass)
|
76
|
-
# {~T: int}
|
79
|
+
# {~T: int, ~K: int}
|
77
80
|
|
78
81
|
get_specialized_type_var_map(IntBarFoo)
|
79
82
|
# {~T: int, ~K: str}
|
@@ -81,43 +84,52 @@ def get_specialized_type_var_map(cls: type) -> Optional[dict[str, type]]:
|
|
81
84
|
"""
|
82
85
|
from strawberry.types.base import has_object_definition
|
83
86
|
|
84
|
-
|
85
|
-
if orig_bases is None:
|
86
|
-
# Specialized generic aliases will not have __orig_bases__
|
87
|
-
if get_origin(cls) is not None and is_generic_alias(cls):
|
88
|
-
orig_bases = (cls,)
|
89
|
-
else:
|
90
|
-
# Not a specialized type
|
91
|
-
return None
|
92
|
-
|
93
|
-
type_var_map = {}
|
94
|
-
|
95
|
-
# only get type vars for base generics (ie. Generic[T]) and for strawberry types
|
96
|
-
|
97
|
-
orig_bases = [b for b in orig_bases if has_object_definition(b)]
|
87
|
+
param_args: dict[TypeVar, Union[TypeVar, type]] = {}
|
98
88
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
type_var_map.update(base_type_var_map)
|
89
|
+
types: list[type] = [cls]
|
90
|
+
while types:
|
91
|
+
tp = types.pop(0)
|
92
|
+
if (origin := get_origin(tp)) is None or origin in (Generic, Protocol):
|
93
|
+
origin = tp
|
105
94
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
params = origin and getattr(origin, "__parameters__", None)
|
110
|
-
if params is None:
|
111
|
-
params = getattr(base, "__parameters__", None)
|
112
|
-
|
113
|
-
if not params:
|
95
|
+
# only get type vars for base generics (i.e. Generic[T]) and for strawberry types
|
96
|
+
if not has_object_definition(origin):
|
114
97
|
continue
|
115
98
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
99
|
+
if (type_params := getattr(origin, "__parameters__", None)) is not None:
|
100
|
+
args = get_args(tp)
|
101
|
+
if args:
|
102
|
+
for type_param, arg in zip(type_params, args):
|
103
|
+
if type_param not in param_args:
|
104
|
+
param_args[type_param] = arg
|
105
|
+
else:
|
106
|
+
for type_param in type_params:
|
107
|
+
if type_param not in param_args:
|
108
|
+
param_args[type_param] = strawberry.UNSET
|
109
|
+
|
110
|
+
if orig_bases := getattr(origin, "__orig_bases__", None):
|
111
|
+
types.extend(orig_bases)
|
112
|
+
if not param_args:
|
113
|
+
return None
|
114
|
+
|
115
|
+
for type_param, arg in list(param_args.items()):
|
116
|
+
resolved_arg = arg
|
117
|
+
while (
|
118
|
+
isinstance(resolved_arg, TypeVar) and resolved_arg is not strawberry.UNSET
|
119
|
+
):
|
120
|
+
resolved_arg = (
|
121
|
+
param_args.get(resolved_arg, strawberry.UNSET)
|
122
|
+
if resolved_arg is not type_param
|
123
|
+
else strawberry.UNSET
|
124
|
+
)
|
125
|
+
|
126
|
+
param_args[type_param] = resolved_arg
|
127
|
+
|
128
|
+
return {
|
129
|
+
k.__name__: v
|
130
|
+
for k, v in reversed(param_args.items())
|
131
|
+
if v is not strawberry.UNSET and not isinstance(v, TypeVar)
|
132
|
+
}
|
121
133
|
|
122
134
|
|
123
135
|
__all__ = ["get_func_args", "get_specialized_type_var_map", "in_async_context"]
|
@@ -223,13 +223,13 @@ strawberry/utils/debug.py,sha256=eP-wyKSSt7YHHY_lJdSa2hDlrBPd72kDtmGdFZ0Kyyo,144
|
|
223
223
|
strawberry/utils/deprecations.py,sha256=Yrp4xBzp36mQprH8qPHpPMhkCLm527q7XU7pP4aar_0,782
|
224
224
|
strawberry/utils/graphql_lexer.py,sha256=JUVJrJ6Ax0t7m6-DTWFzf4cvXrC02VPmL1NS2zMEMbY,1255
|
225
225
|
strawberry/utils/importer.py,sha256=NtTgNaNSW4TnlLo_S34nxXq14RxUAec-QlEZ0LON28M,629
|
226
|
-
strawberry/utils/inspect.py,sha256
|
226
|
+
strawberry/utils/inspect.py,sha256=-aFT65PkQ9KXo5w8Q2uveBJ8jEpi40sTqRipRQVdYR8,3406
|
227
227
|
strawberry/utils/logging.py,sha256=U1cseHGquN09YFhFmRkiphfASKCyK0HUZREImPgVb0c,746
|
228
228
|
strawberry/utils/operation.py,sha256=SSXxN-vMqdHO6W2OZtip-1z7y4_A-eTVFdhDvhKeLCk,1193
|
229
229
|
strawberry/utils/str_converters.py,sha256=-eH1Cl16IO_wrBlsGM-km4IY0IKsjhjnSNGRGOwQjVM,897
|
230
230
|
strawberry/utils/typing.py,sha256=Ux0Hl46lhuXvOKK-C5hj6nlz3zDn8P4CUGH2nUVD2vU,13373
|
231
|
-
strawberry_graphql-0.
|
232
|
-
strawberry_graphql-0.
|
233
|
-
strawberry_graphql-0.
|
234
|
-
strawberry_graphql-0.
|
235
|
-
strawberry_graphql-0.
|
231
|
+
strawberry_graphql-0.260.0.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
|
232
|
+
strawberry_graphql-0.260.0.dist-info/METADATA,sha256=YXvVSrWaUwwRiAhSjY0TYToBMFkQltM4_rkL8BZQDmE,7539
|
233
|
+
strawberry_graphql-0.260.0.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
234
|
+
strawberry_graphql-0.260.0.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
|
235
|
+
strawberry_graphql-0.260.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
{strawberry_graphql-0.259.1.dist-info → strawberry_graphql-0.260.0.dist-info}/entry_points.txt
RENAMED
File without changes
|