Extracts the value from a TypeAliasType, recursively exploring unions and inner TypeAliasType to flatten them into a single set. Forward references are not evaluated, so no recursive exploration happens into them.
(type_: _AnnotationScanType)
| 351 | |
| 352 | |
| 353 | def pep695_values(type_: _AnnotationScanType) -> Set[Any]: |
| 354 | """Extracts the value from a TypeAliasType, recursively exploring unions |
| 355 | and inner TypeAliasType to flatten them into a single set. |
| 356 | |
| 357 | Forward references are not evaluated, so no recursive exploration happens |
| 358 | into them. |
| 359 | """ |
| 360 | _seen = set() |
| 361 | |
| 362 | def recursive_value(inner_type): |
| 363 | if inner_type in _seen: |
| 364 | # recursion are not supported (at least it's flagged as |
| 365 | # an error by pyright). Just avoid infinite loop |
| 366 | return inner_type |
| 367 | _seen.add(inner_type) |
| 368 | if not is_pep695(inner_type): |
| 369 | return inner_type |
| 370 | value = inner_type.__value__ |
| 371 | if not is_union(value): |
| 372 | return value |
| 373 | return [recursive_value(t) for t in value.__args__] |
| 374 | |
| 375 | res = recursive_value(type_) |
| 376 | if isinstance(res, list): |
| 377 | types = set() |
| 378 | stack = deque(res) |
| 379 | while stack: |
| 380 | t = stack.popleft() |
| 381 | if isinstance(t, list): |
| 382 | stack.extend(t) |
| 383 | else: |
| 384 | types.add(None if t is NoneType or is_fwd_none(t) else t) |
| 385 | return types |
| 386 | else: |
| 387 | return {res} |
| 388 | |
| 389 | |
| 390 | @overload |
no test coverage detected