diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2022-09-08 19:00:08 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2022-09-08 19:00:08 +0000 |
commit | 479dbc99e7fc5a60f846992c0cca8542047a8933 (patch) | |
tree | 15210296871b450b22ffdc9535f204ed6fa78a21 /lib/sqlalchemy/util/typing.py | |
parent | b0e5667a79fdf096719c0ad596d5aa6e9753adb7 (diff) | |
parent | fcd298e1afe9b309de34d28b35e4debc3940d6b9 (diff) | |
download | sqlalchemy-479dbc99e7fc5a60f846992c0cca8542047a8933.tar.gz |
Merge "additional de-stringify pass for unions" into main
Diffstat (limited to 'lib/sqlalchemy/util/typing.py')
-rw-r--r-- | lib/sqlalchemy/util/typing.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/sqlalchemy/util/typing.py b/lib/sqlalchemy/util/typing.py index 85c1bae72..a0d59a630 100644 --- a/lib/sqlalchemy/util/typing.py +++ b/lib/sqlalchemy/util/typing.py @@ -120,6 +120,19 @@ def de_stringify_annotation( return annotation # type: ignore +def de_stringify_union_elements( + cls: Type[Any], + annotation: _AnnotationScanType, + str_cleanup_fn: Optional[Callable[[str], str]] = None, +) -> Type[Any]: + return make_union_type( + *[ + de_stringify_annotation(cls, anno, str_cleanup_fn) + for anno in annotation.__args__ # type: ignore + ] + ) + + def is_pep593(type_: Optional[_AnnotationScanType]) -> bool: return type_ is not None and typing_get_origin(type_) is Annotated @@ -186,7 +199,7 @@ def expand_unions( return (type_,) -def is_optional(type_): +def is_optional(type_: Any) -> bool: return is_origin_of( type_, "Optional", @@ -199,7 +212,7 @@ def is_optional_union(type_: Any) -> bool: return is_optional(type_) and NoneType in typing_get_args(type_) -def is_union(type_): +def is_union(type_: Any) -> bool: return is_origin_of(type_, "Union") |