Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose ExpressionField, use __slots__ for several class #1038

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions beanie/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
BackLink,
BeanieObjectId,
DeleteRules,
ExpressionField,
Indexed,
Link,
PydanticObjectId,
Expand Down Expand Up @@ -74,6 +75,7 @@
"BackLink",
"WriteRules",
"DeleteRules",
"ExpressionField",
# Custom Types
"DecimalAnnotation",
"BsonBinary",
Expand Down
2 changes: 2 additions & 0 deletions beanie/odm/bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class Config:


class BulkWriter:
__slots__ = ("operations", "session", "ordered")

def __init__(
self,
session: Optional[AsyncIOMotorClientSession] = None,
Expand Down
2 changes: 2 additions & 0 deletions beanie/odm/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class CachedItem(BaseModel):


class LRUCache:
__slots__ = ("capacity", "expiration_time", "cache")

def __init__(self, capacity: int, expiration_time: timedelta):
self.capacity: int = capacity
self.expiration_time: timedelta = expiration_time
Expand Down
16 changes: 7 additions & 9 deletions beanie/odm/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,7 @@
from pymongo import ASCENDING, IndexModel

from beanie.odm.enums import SortDirection
from beanie.odm.operators.find.comparison import (
GT,
GTE,
LT,
LTE,
NE,
Eq,
In,
)
from beanie.odm.operators.find.comparison import GT, GTE, LT, LTE, NE, Eq, In
from beanie.odm.registry import DocsRegistry
from beanie.odm.utils.parsing import parse_obj
from beanie.odm.utils.pydantic import (
Expand Down Expand Up @@ -138,6 +130,8 @@ class PydanticObjectId(ObjectId):
Object Id field. Compatible with Pydantic.
"""

__slots__ = ()

@classmethod
def __get_validators__(cls):
yield cls.validate
Expand Down Expand Up @@ -206,6 +200,8 @@ def __modify_schema__(cls, field_schema):


class ExpressionField(str):
__slots__ = ()

def __getitem__(self, item):
"""
Get sub field
Expand Down Expand Up @@ -511,6 +507,8 @@ def to_dict(self):


class IndexModelField:
__slots__ = ("index", "name", "fields", "options")

def __init__(self, index: IndexModel):
self.index = index
self.name = index.document["name"]
Expand Down
Loading