Skip to content

Commit

Permalink
[0.1.11] Enforce null type checks for SchemaField
Browse files Browse the repository at this point in the history
Support for plain methods/arbitrary objects in `default=` argument
  • Loading branch information
surenkov committed Sep 14, 2022
1 parent e378a34 commit 3e785d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
28 changes: 12 additions & 16 deletions django_pydantic_field/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,37 +148,33 @@ def _deconstruct_config(self, kwargs):
kwargs.update(self.export_params, config=self.config)


if t.TYPE_CHECKING:
OptSchemaT = t.Optional[base.SchemaT]

@t.overload
def SchemaField(
schema: t.Union[t.Type["base.ST"], "t.ForwardRef", str] = ...,
schema: "t.Union[t.Type[base.ST], t.ForwardRef, str]" = ...,
config: "base.ConfigType" = ...,
default: t.Union["base.ST", t.Type[NOT_PROVIDED], None] = ...,
null: t.Literal[True] = ...,
default: "t.Union[OptSchemaT, t.Callable[[], OptSchemaT]]" = ...,
*args,
null: "t.Literal[True]",
**kwargs,
) -> t.Any:
) -> "t.Optional[base.ST]":
...


@t.overload
def SchemaField(
schema: t.Union[t.Type["base.ST"], "t.ForwardRef", str] = ...,
schema: "t.Union[t.Type[base.ST], t.ForwardRef, str]" = ...,
config: "base.ConfigType" = ...,
default: t.Union["base.ST", t.Type[NOT_PROVIDED]] = ...,
null: t.Literal[False] = ...,
default: "t.Union[base.SchemaT, t.Callable[[], base.SchemaT]]" = ...,
*args,
null: "t.Literal[False]" = ...,
**kwargs,
) -> t.Any:
) -> "base.ST":
...


def SchemaField(
schema: t.Union[t.Type["base.ST"], "t.ForwardRef", str] = None,
config: "base.ConfigType" = None,
default: t.Union["base.ST", t.Type[NOT_PROVIDED], None] = NOT_PROVIDED,
*args,
**kwargs,
) -> t.Any:
def SchemaField(schema=None, config=None, default=NOT_PROVIDED, *args, **kwargs) -> t.Any:
kwargs.update(schema=schema, config=config, default=default)
return PydanticSchemaField(*args, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = django-pydantic-field
version = 0.1.10
version = 0.1.11
url = https://github.com/surenkov/django-pydantic-field

description = Django JSONField with Pydantic models as a Schema
Expand Down

0 comments on commit 3e785d7

Please sign in to comment.