Skip to content

Commit

Permalink
add: nullable field support (sbdchd#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
chdsbd authored Apr 15, 2021
1 parent 5e361f3 commit a31b1b4
Show file tree
Hide file tree
Showing 4 changed files with 836 additions and 151 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mongo-types"
version = "0.7.7"
version = "0.8.0"
description = "Type stubs for mongoengine w/ basic support for bson and pymongo"
repository = "https://github.com/sbdchd/mongo-types"
readme = "README.md"
Expand Down
20 changes: 18 additions & 2 deletions typings/mongoengine/base.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Tuple, Type, TypeVar
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, TypeVar, Union

from bson import SON

Expand All @@ -25,4 +25,20 @@ class BaseDocument:
) -> U: ...

class BaseField:
pass
def __new__(
cls,
db_field: str = ...,
name: Optional[str] = ...,
required: bool = ...,
default: Union[Any, None, Callable[[], Any]] = ...,
primary_key: bool = ...,
choices: Optional[List[Any]] = ...,
null: bool = ...,
verbose_name: Optional[str] = ...,
help_text: Optional[str] = ...,
) -> BaseField: ...
def __set__(self, instance: Any, value: Any) -> None: ...
def __get__(self, instance: Any, owner: Any) -> Any: ...
def validate(self, value: Any, clean: bool = ...) -> None: ...

class ComplexBaseField(BaseField): ...
4 changes: 2 additions & 2 deletions typings/mongoengine/document.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Document(BaseDocument):
_meta: _UnderMetaDict
_fields: Dict[str, Any]

pk = StringField()
pk = StringField(required=True)
@classmethod
def _get_collection(cls) -> Collection: ...
# NOTE(sbdchd): if we are willing to change all Document.objects.filter()
Expand Down Expand Up @@ -67,7 +67,7 @@ class Document(BaseDocument):
class EmbeddedDocument(BaseDocument):
_fields: Dict[str, Any]
_meta: _UnderMetaDict
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def __new__(cls, *args: Any, **kwargs: Any) -> EmbeddedDocument: ...
def save(self) -> None: ...
def __contains__(self, key: str) -> bool: ...
def __getitem__(self, key: str) -> Any: ...
Expand Down
Loading

0 comments on commit a31b1b4

Please sign in to comment.