-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
269 Stop multi-dimensional array and email filtering from breaking (#270
) * stop multidimensional arrays from breaking `FastAPIWrapper` * replace `list[list]` with `list` * fix linter errors * wip * fix `ModelFilters` * update `pydantic_model_filters` * use `Array. _get_dimensions` instead of `is_multidimensional_array` * use latest piccolo * ignore mypy warning * add test for filtering email * add a test for multidimensional arrays
- Loading branch information
1 parent
2df940d
commit 9dc8f41
Showing
10 changed files
with
317 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
""" | ||
Utils for extracting information from complex, nested types. | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
import typing as t | ||
|
||
try: | ||
# Python 3.10 and above | ||
from types import UnionType # type: ignore | ||
except ImportError: | ||
|
||
class UnionType: # type: ignore | ||
... | ||
|
||
|
||
def get_type(type_: t.Type) -> t.Type: | ||
""" | ||
Extract the inner type from an optional if necessary, otherwise return | ||
the type as is. | ||
For example:: | ||
>>> get_type(Optional[int]) | ||
int | ||
>>> get_type(int | None) | ||
int | ||
>>> get_type(int) | ||
int | ||
>>> _get_type(list[str]) | ||
list[str] | ||
""" | ||
origin = t.get_origin(type_) | ||
|
||
# Note: even if `t.Optional` is passed in, the origin is still a | ||
# `t.Union` or `UnionType` depending on the Python version. | ||
if any(origin is i for i in (t.Union, UnionType)): | ||
union_args = t.get_args(type_) | ||
|
||
NoneType = type(None) | ||
|
||
if len(union_args) == 2 and NoneType in union_args: | ||
return [i for i in union_args if i is not NoneType][0] | ||
|
||
return type_ | ||
|
||
|
||
__all__ = ("get_type",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
black==24.3.0 | ||
isort==5.12.0 | ||
twine==4.0.2 | ||
mypy==1.5.1 | ||
isort==5.13.2 | ||
twine==5.0.0 | ||
mypy==1.9.0 | ||
pip-upgrader==1.4.15 | ||
wheel==0.41.2 | ||
setuptools==68.2.2 | ||
wheel==0.43.0 | ||
setuptools==69.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.