Skip to content

Commit

Permalink
Merge pull request #201 from nzsmith1/pytype
Browse files Browse the repository at this point in the history
Add support for py.typed file
  • Loading branch information
roman-right authored Feb 11, 2022
2 parents 0f06c0d + d0706ab commit cf848b8
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion beanie/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from beanie.odm.utils.general import init_beanie
from beanie.odm.documents import Document

__version__ = "1.9.0"
__version__ = "1.9.1"
__all__ = [
# ODM
"Document",
Expand Down
9 changes: 7 additions & 2 deletions beanie/odm/operators/find/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Sample(Document):
<https://docs.mongodb.com/manual/reference/operator/query/mod/>
"""

def __init__(self, field, divisor, remainder):
def __init__(self, field, divisor: int, remainder: int):
self.field = field
self.divisor = divisor
self.remainder = remainder
Expand All @@ -97,7 +97,12 @@ class RegEx(BaseFindEvaluationOperator):
<https://docs.mongodb.com/manual/reference/operator/query/regex/>
"""

def __init__(self, field, pattern, options: Optional[str] = None):
def __init__(
self,
field,
pattern: str,
options: Optional[str] = None,
):
self.field = field
self.pattern = pattern
self.options = options
Expand Down
4 changes: 3 additions & 1 deletion beanie/odm/queries/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

from pydantic import BaseModel

from motor.core import AgnosticCommandCursor

from beanie.odm.cache import LRUCache
from beanie.odm.interfaces.session import SessionMethods
from beanie.odm.queries.cursor import BaseCursorQuery
Expand Down Expand Up @@ -96,7 +98,7 @@ def get_aggregation_pipeline(
return match_pipeline + self.aggregation_pipeline + projection_pipeline

@property
def motor_cursor(self):
def motor_cursor(self) -> AgnosticCommandCursor:
aggregation_pipeline = self.get_aggregation_pipeline()
return self.document_model.get_motor_collection().aggregate(
aggregation_pipeline, session=self.session
Expand Down
5 changes: 1 addition & 4 deletions beanie/odm/queries/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,7 @@ def delete(
bulk_writer=bulk_writer,
).set_session(session=session)

def project(
self,
projection_model,
):
def project(self, projection_model):
"""
Apply projection parameter
:param projection_model: Optional[Type[BaseModel]] - projection model
Expand Down
4 changes: 3 additions & 1 deletion beanie/odm/settings/general.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from dataclasses import dataclass
from typing import Type
from motor.motor_asyncio import AsyncIOMotorDatabase

from beanie.odm.settings.collection import CollectionSettings
from beanie.odm.settings.model import ModelSettings
Expand All @@ -10,7 +12,7 @@ class DocumentSettings:
collection_settings: CollectionSettings

@classmethod
async def init(cls, database, document_model, allow_index_dropping):
async def init(cls, database: AsyncIOMotorDatabase, document_model: Type, allow_index_dropping: bool):
# Init collection settings
collection_settings = await CollectionSettings.init(
database=database,
Expand Down
Empty file added beanie/py.typed
Empty file.
15 changes: 14 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

Beanie project

## [1.9.1] - 2022-02-11

### Improvement

- Add support for py.typed file

### Implementation

- Author - [Nicholas Smith](https://github.com/nzsmith1)
- PR - <https://github.com/roman-right/beanie/pull/201>

## [1.9.0] - 2022-02-11

### Breaking Change
Expand Down Expand Up @@ -687,4 +698,6 @@ how specific type should be presented in the database

[1.8.13]: https://pypi.org/project/beanie/1.8.13

[1.9.0]: https://pypi.org/project/beanie/1.9.0
[1.9.0]: https://pypi.org/project/beanie/1.9.0

[1.9.1]: https://pypi.org/project/beanie/1.9.1
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "beanie"
version = "1.9.0"
version = "1.9.1"
description = "Asynchronous Python ODM for MongoDB"
authors = ["Roman <[email protected]>"]
license = "Apache-2.0"
Expand All @@ -9,6 +9,7 @@ repository = "https://github.com/roman-right/beanie"
keywords = ["mongodb", "odm", "orm", "pydantic", "mongo", "async", "python"]
include = [
"LICENSE",
"beanie/py.typed"
]
readme = "README.md"

Expand Down
2 changes: 1 addition & 1 deletion tests/test_beanie.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


def test_version():
assert __version__ == "1.9.0"
assert __version__ == "1.9.1"

0 comments on commit cf848b8

Please sign in to comment.