diff --git a/poetry.lock b/poetry.lock index 06c0836..a3e40eb 100644 --- a/poetry.lock +++ b/poetry.lock @@ -15,6 +15,14 @@ optional = false python-versions = "*" version = "0.1.0" +[[package]] +category = "dev" +description = "Classes Without Boilerplate" +name = "attrs" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "20.3.0" + [[package]] category = "dev" description = "Specifications for callback functions passed in to an API" @@ -83,6 +91,19 @@ pyflakes = ">=2.2.0,<2.3.0" python = "<3.8" version = "*" +[[package]] +category = "dev" +description = "A plugin for flake8 to enable linting .pyi files." +name = "flake8-pyi" +optional = false +python-versions = ">=3.6" +version = "20.10.0" + +[package.dependencies] +attrs = "*" +flake8 = ">=3.2.1" +pyflakes = ">=2.1.1" + [[package]] category = "dev" description = "Read metadata from Python packages" @@ -349,18 +370,20 @@ python-versions = ">=3.6" version = "3.4.0" [metadata] -content-hash = "8b6a7794da851be2d1fc16275cb0e97a5f9a1141f7143aae43d2dd322e2f1559" +content-hash = "38a406c7fb85d0c7d1d1e998ad8ebd8a200d9d1bc4919dd50c1a6fa3d1e13943" python-versions = "^3.7" [metadata.hashes] appdirs = ["7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41", "a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128"] appnope = ["5b26757dc6f79a3b7dc9fab95359328d5747fcb2409d331ea66d0272b90ab2a0", "8b995ffe925347a2138d7ac0fe77155e4311a0ea6d6da4f5128fe4b3cbe5ed71"] +attrs = ["31b2eced602aa8423c2aea9c76a724617ed67cf9513173fd3a4f03e3a929c7e6", "832aa3cde19744e49938b91fea06d69ecb9e649c93ba974535d08ad92164f700"] backcall = ["5cbdbf27be5e7cfadb448baf0aa95508f91f2bbc6c6437cd9cd06e2a4c215e1e", "fbbce6a29f263178a1f7915c1940bde0ec2b2a967566fe1c65c1dfb7422bd255"] black = ["1c02557aa099101b9d21496f8a914e9ed2222ef70336404eeeac8edba836fbea"] click = ["d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a", "dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc"] colorama = ["5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b", "9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"] decorator = ["41fa54c2a0cc4ba648be4fd43cff00aedf5b9465c9bf18d64325bc225f08f760", "e3a62f0520172440ca0dcc823749319382e377f37f140a0b99ef45fecb84bfe7"] flake8 = ["749dbbd6bfd0cf1318af27bf97a14e28e5ff548ef8e5b1566ccfb25a11e7c839", "aadae8761ec651813c24be05c6f7b4680857ef6afaae4651a4eccaef97ce6c3b"] +flake8-pyi = ["cee3b20a5123152c697870e7e800b60e3c95eb89e272a2b63d8cf55cafb0472c", "ff5dfc40bffa878f6ce95bcfd9a6ad14c44b85cbe99c4864e729301bf54267f0"] importlib-metadata = ["77a540690e24b0305878c37ffd421785a6f7e53c8b5720d211b211de8d0e95da", "cefa1a2f919b866c5beb7c9f7b0ebb4061f30a8a9bf16d609b000e2dfaceb9c3"] ipython = ["c987e8178ced651532b3b1ff9965925bfd445c279239697052561a9ab806d28f", "cbb2ef3d5961d44e6a963b9817d4ea4e1fa2eb589c371a470fed14d8d40cbd6a"] ipython-genutils = ["72dd37233799e619666c9f639a9da83c34013a73e8bbc79a7a6348d93c61fab8", "eb2e116e75ecef9d4d228fdc66af54269afa26ab4463042e33785b887c628ba8"] @@ -384,7 +407,7 @@ regex = ["02951b7dacb123d8ea6da44fe45ddd084aa6777d4b2454fa0da61d569c6fa538", "0d six = ["30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259", "8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced"] toml = ["806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b", "b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"] traitlets = ["178f4ce988f69189f7e523337a3e11d91c786ded9360174a3d9ca83e79bc5396", "69ff3f9d5351f31a7ad80443c2674b7099df13cc41fc5fa6e2f6d3b0330b0426"] -typed-ast = ["0666aa36131496aed8f7be0410ff974562ab7eeac11ef351def9ea6fa28f6355", "0c2c07682d61a629b68433afb159376e24e5b2fd4641d35424e462169c0a7919", "0d8110d78a5736e16e26213114a38ca35cb15b6515d535413b090bd50951556d", "249862707802d40f7f29f6e1aad8d84b5aa9e44552d2cc17384b209f091276aa", "24995c843eb0ad11a4527b026b4dde3da70e1f2d8806c99b7b4a7cf491612652", "269151951236b0f9a6f04015a9004084a5ab0d5f19b57de779f908621e7d8b75", "3742b32cf1c6ef124d57f95be609c473d7ec4c14d0090e5a5e05a15269fb4d0c", "4083861b0aa07990b619bd7ddc365eb7fa4b817e99cf5f8d9cf21a42780f6e01", "498b0f36cc7054c1fead3d7fc59d2150f4d5c6c56ba7fb150c013fbc683a8d2d", "4e3e5da80ccbebfff202a67bf900d081906c358ccc3d5e3c8aea42fdfdfd51c1", "6daac9731f172c2a22ade6ed0c00197ee7cc1221aa84cfdf9c31defeb059a907", "715ff2f2df46121071622063fc7543d9b1fd19ebfc4f5c8895af64a77a8c852c", "73d785a950fc82dd2a25897d525d003f6378d1cb23ab305578394694202a58c3", "7e4c9d7658aaa1fc80018593abdf8598bf91325af6af5cce4ce7c73bc45ea53d", "8c8aaad94455178e3187ab22c8b01a3837f8ee50e09cf31f1ba129eb293ec30b", "8ce678dbaf790dbdb3eba24056d5364fb45944f33553dd5869b7580cdbb83614", "92c325624e304ebf0e025d1224b77dd4e6393f18aab8d829b5b7e04afe9b7a2c", "aaee9905aee35ba5905cfb3c62f3e83b3bec7b39413f0a7f19be4e547ea01ebb", "b52ccf7cfe4ce2a1064b18594381bccf4179c2ecf7f513134ec2f993dd4ab395", "bcd3b13b56ea479b3650b82cabd6b5343a625b0ced5429e4ccad28a8973f301b", "c9e348e02e4d2b4a8b2eedb48210430658df6951fa484e59de33ff773fbd4b41", "d205b1b46085271b4e15f670058ce182bd1199e56b317bf2ec004b6a44f911f6", "d43943ef777f9a1c42bf4e552ba23ac77a6351de620aa9acf64ad54933ad4d34", "d5d33e9e7af3b34a40dc05f498939f0ebf187f07c385fd58d591c533ad8562fe", "d648b8e3bf2fe648745c8ffcee3db3ff903d0817a01a12dd6a6ea7a8f4889072", "f208eb7aff048f6bea9586e61af041ddf7f9ade7caed625742af423f6bae3298", "fac11badff8313e23717f3dada86a15389d0708275bddf766cca67a84ead3e91", "fc0fea399acb12edbf8a628ba8d2312f583bdbdb3335635db062fa98cf71fca4", "fcf135e17cc74dbfbc05894ebca928ffeb23d9790b3167a674921db19082401f", "fe460b922ec15dd205595c9b5b99e2f056fd98ae8f9f56b888e7a17dc2b757e7"] +typed-ast = ["0666aa36131496aed8f7be0410ff974562ab7eeac11ef351def9ea6fa28f6355", "0c2c07682d61a629b68433afb159376e24e5b2fd4641d35424e462169c0a7919", "249862707802d40f7f29f6e1aad8d84b5aa9e44552d2cc17384b209f091276aa", "24995c843eb0ad11a4527b026b4dde3da70e1f2d8806c99b7b4a7cf491612652", "269151951236b0f9a6f04015a9004084a5ab0d5f19b57de779f908621e7d8b75", "4083861b0aa07990b619bd7ddc365eb7fa4b817e99cf5f8d9cf21a42780f6e01", "498b0f36cc7054c1fead3d7fc59d2150f4d5c6c56ba7fb150c013fbc683a8d2d", "4e3e5da80ccbebfff202a67bf900d081906c358ccc3d5e3c8aea42fdfdfd51c1", "6daac9731f172c2a22ade6ed0c00197ee7cc1221aa84cfdf9c31defeb059a907", "715ff2f2df46121071622063fc7543d9b1fd19ebfc4f5c8895af64a77a8c852c", "73d785a950fc82dd2a25897d525d003f6378d1cb23ab305578394694202a58c3", "8c8aaad94455178e3187ab22c8b01a3837f8ee50e09cf31f1ba129eb293ec30b", "8ce678dbaf790dbdb3eba24056d5364fb45944f33553dd5869b7580cdbb83614", "aaee9905aee35ba5905cfb3c62f3e83b3bec7b39413f0a7f19be4e547ea01ebb", "bcd3b13b56ea479b3650b82cabd6b5343a625b0ced5429e4ccad28a8973f301b", "c9e348e02e4d2b4a8b2eedb48210430658df6951fa484e59de33ff773fbd4b41", "d205b1b46085271b4e15f670058ce182bd1199e56b317bf2ec004b6a44f911f6", "d43943ef777f9a1c42bf4e552ba23ac77a6351de620aa9acf64ad54933ad4d34", "d5d33e9e7af3b34a40dc05f498939f0ebf187f07c385fd58d591c533ad8562fe", "fc0fea399acb12edbf8a628ba8d2312f583bdbdb3335635db062fa98cf71fca4", "fe460b922ec15dd205595c9b5b99e2f056fd98ae8f9f56b888e7a17dc2b757e7"] typing-extensions = ["7cb407020f00f7bfc3cb3e7881628838e69d8f3fcab2f64742a5e76b2f841918", "99d4073b617d30288f569d3f13d2bd7548c3a7e4c8de87db09a9d29bb3a4a60c", "dafc7639cde7f1b6e1acc0f457842a83e722ccca8eef5270af2d74792619a89f"] wcwidth = ["beb4802a9cebb9144e99086eff703a642a13d6a0052920003a230f3294bbe784", "c4d647b99872929fdb7bdcaa4fbe7f01413ed3d98077df798530e5b04f116c83"] wheel = ["78b5b185f0e5763c26ca1e324373aadd49182ca90e825f7853f4b2509215dc0e", "e11eefd162658ea59a60a0f6c7d493a7190ea4b9a85e335b33489d9f17e0245e"] diff --git a/pyproject.toml b/pyproject.toml index 03de0df..7f64201 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,6 +25,7 @@ flake8 = "^3.8" black = {version = "20.8b1",allows-prereleases = true} isort = "^4.3" wheel = "^0.36.2" +flake8-pyi = "^20.10" [build-system] requires = ["poetry>=0.12", "setuptools"] diff --git a/tests/test_mongoengine.py b/tests/test_mongoengine.py index f84badb..aca02a3 100644 --- a/tests/test_mongoengine.py +++ b/tests/test_mongoengine.py @@ -118,12 +118,18 @@ def main() -> None: # reveal_type(posts) # Revealed type is 'builtins.list[test_mongoengine.Post*] + posts_again = Post.objects().exclude("title").all_fields() + print(posts_again) + insert_result = Post.objects().insert([Post(), Post()]) print(insert_result) insert_result_2 = Post.objects().insert([Post(), Post()], load_bulk=False) print(insert_result_2) + res: int = Post.objects().update(foo=True) + print(res) + first_post = posts[0] first_post.tags.values() first_post.errors diff --git a/typings/mongoengine/queryset/queryset.pyi b/typings/mongoengine/queryset/queryset.pyi index e2f19e0..ca6bac8 100644 --- a/typings/mongoengine/queryset/queryset.pyi +++ b/typings/mongoengine/queryset/queryset.pyi @@ -15,15 +15,19 @@ from typing import ( from bson import ObjectId from mongoengine.queryset.visitor import Q +from pymongo.collation import Collation from pymongo.collection import Collection from pymongo.command_cursor import CommandCursor from pymongo.cursor import Cursor +from pymongo.read_preferences import _ServerMode from typing_extensions import Literal _T = TypeVar("_T") _U = TypeVar("_U", bound="QuerySet[Any]") +_ReadWriteConcern = Dict[str, Union[str, int, bool]] + class QuerySet(Generic[_T]): _document: Type[_T] _collection: Collection @@ -40,7 +44,7 @@ class QuerySet(Generic[_T]): self, doc_or_docs: Union[_T, List[_T]], load_bulk: Literal[False], - write_concern: Optional[Any] = ..., + write_concern: Optional[_ReadWriteConcern] = ..., signal_kwargs: Optional[Any] = ..., ) -> List[ObjectId]: ... @overload @@ -48,23 +52,51 @@ class QuerySet(Generic[_T]): self, doc_or_docs: Union[_T, List[_T]], load_bulk: Literal[True] = ..., - write_concern: Optional[Any] = ..., + write_concern: Optional[_ReadWriteConcern] = ..., signal_kwargs: Optional[Any] = ..., ) -> List[_T]: ... def values(self, *args: str) -> Dict[str, Any]: ... def as_pymongo(self) -> QuerySet[Dict[str, Any]]: ... + def scalar(self, *fields: str) -> List[Any]: ... def values_list(self, *args: str) -> List[Any]: ... - def update(self, *args: Q, **kwargs: object) -> int: ... + def update( + self, + upsert: bool = ..., + multi: bool = ..., + write_concern: Optional[_ReadWriteConcern] = ..., + read_concern: Optional[_ReadWriteConcern] = ..., + **update: object + ) -> int: ... def update_one( - self, upsert: bool = ..., write_concern: Optional[Any] = ..., **update: object + self, + upsert: bool = ..., + write_concern: Optional[_ReadWriteConcern] = ..., + **update: object ) -> int: ... + def upsert_one( + self, + write_concern: Optional[_ReadWriteConcern] = ..., + read_concern: Optional[_ReadWriteConcern] = ..., + **update: object + ) -> _T: ... def delete(self) -> None: ... def filter(self: _U, *args: Q, **kwargs: object) -> _U: ... def none(self: _U) -> _U: ... - def read_preference(self: _U, read_preference: object) -> _U: ... - def only(self: _U, *args: str) -> _U: ... - def order_by(self: _U, *args: str) -> _U: ... + def read_preference(self: _U, read_preference: _ServerMode) -> _U: ... + def rewind(self: _U) -> _U: ... + def only(self: _U, *fields: str) -> _U: ... + def exclude(self: _U, *args: str) -> _U: ... + def exec_js(self: _U, code: str, *fields: str, **options: Any) -> _U: ... + def explain(self) -> Any: ... + def all_fields(self: _U) -> _U: ... + def average(self: _U, field: str) -> _U: ... + def batch_size(self: _U, size: int) -> _U: ... + def clone(self: _U) -> _U: ... + def collation(self: _U, collation: Optional[Collation] = ...) -> _U: ... + def comment(self: _U, text: str) -> _U: ... + def order_by(self: _U, *keys: str) -> _U: ... def skip(self: _U, amount: Optional[int]) -> _U: ... + def sum(self, field: str) -> float: ... def limit(self: _U, amount: int) -> _U: ... def count(self) -> int: ... def __iter__(self) -> Iterator[_T]: ... @@ -72,6 +104,16 @@ class QuerySet(Generic[_T]): def all(self: _U) -> _U: ... def aggregate(self, *args: object, allowDiskUse: bool = ...) -> CommandCursor: ... def max_time_ms(self: _U, ms: Optional[int]) -> _U: ... + def modify( + self: _U, + upsert: bool = ..., + full_response: bool = ..., + remove: bool = ..., + new: bool = ..., + **update: object + ) -> _U: ... + def no_cache(self: _U) -> _U: ... + def no_dereference(self: _U) -> _U: ... def create(self, **kwargs: object) -> _T: ... def distinct(self, field: str) -> List[Any]: ... def __getitem__(self, key: int) -> _T: ... diff --git a/typings/pymongo/read_preferences.pyi b/typings/pymongo/read_preferences.pyi index 0a7b21c..e37799a 100644 --- a/typings/pymongo/read_preferences.pyi +++ b/typings/pymongo/read_preferences.pyi @@ -1,6 +1,13 @@ +class _ServerMode: ... +class Primary(_ServerMode): ... +class PrimaryPreferred(_ServerMode): ... +class Secondary(_ServerMode): ... +class SecondaryPreferred(_ServerMode): ... +class Nearest(_ServerMode): ... + class ReadPreference: - NEAREST: object - PRIMARY: object - PRIMARY_PREFERRED: object - SECONDARY: object - SECONDARY_PREFERRED: object + NEAREST: Nearest + PRIMARY: Primary + PRIMARY_PREFERRED: PrimaryPreferred + SECONDARY: Secondary + SECONDARY_PREFERRED: SecondaryPreferred