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

3.13 no deprecate #1062

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
6 changes: 4 additions & 2 deletions .github/workflows/github-actions-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12", "3.13" ]
mongodb-version: [4.4, 5.0, 6.0, 7.0, 8.0 ]
pydantic-version: [ "1.10.18", "2.9.2" ]
runs-on: ubuntu-latest
Expand All @@ -35,4 +35,6 @@ jobs:
- name: install pydantic
run: pip install pydantic==${{ matrix.pydantic-version }}
- name: run tests
run: pytest -v
env:
PYTHON_JIT: 1
run: pytest -v
34 changes: 15 additions & 19 deletions beanie/odm/fields.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import asyncio
import sys
from collections import OrderedDict
from dataclasses import dataclass
from enum import Enum
Expand All @@ -10,23 +11,18 @@
Generic,
List,
Optional,
Tuple,
Type,
TypeVar,
Union,
)

if sys.version_info >= (3, 8):
from typing import get_args
else:
from typing_extensions import get_args

from typing import OrderedDict as OrderedDictType
from typing import Tuple

from bson import DBRef, ObjectId
from bson.errors import InvalidId
from pydantic import BaseModel
from pymongo import ASCENDING, IndexModel
from typing_extensions import get_args

from beanie.odm.enums import SortDirection
from beanie.odm.operators.find.comparison import (
Expand Down Expand Up @@ -307,19 +303,19 @@ def __init__(self, ref: DBRef, document_class: Type[T]):
self.ref = ref
self.document_class = document_class

async def fetch(self, fetch_links: bool = False) -> Union[T, "Link"]:
async def fetch(self, fetch_links: bool = False) -> Union[T, Link]:
result = await self.document_class.get( # type: ignore
self.ref.id, with_children=True, fetch_links=fetch_links
)
return result or self

@classmethod
async def fetch_one(cls, link: "Link"):
async def fetch_one(cls, link: Link):
return await link.fetch()

@classmethod
async def fetch_list(
cls, links: List[Union["Link", "DocType"]], fetch_links: bool = False
cls, links: List[Union[Link, DocType]], fetch_links: bool = False
):
"""
Fetch list that contains links and documents
Expand Down Expand Up @@ -355,7 +351,7 @@ async def fetch_list(

@staticmethod
def repack_links(
links: List[Union["Link", "DocType"]],
links: List[Union[Link, DocType]],
) -> OrderedDictType[Any, Any]:
result = OrderedDict()
for link in links:
Expand All @@ -366,7 +362,7 @@ def repack_links(
return result

@classmethod
async def fetch_many(cls, links: List["Link"]):
async def fetch_many(cls, links: List[Link]):
coros = []
for link in links:
coros.append(link.fetch())
Expand All @@ -375,7 +371,7 @@ async def fetch_many(cls, links: List["Link"]):
if IS_PYDANTIC_V2:

@staticmethod
def serialize(value: Union["Link", BaseModel]):
def serialize(value: Union[Link, BaseModel]):
if isinstance(value, Link):
return value.to_dict()
return value.model_dump(mode="json")
Expand Down Expand Up @@ -540,7 +536,7 @@ def __repr__(self):

@staticmethod
def list_difference(
left: List["IndexModelField"], right: List["IndexModelField"]
left: List[IndexModelField], right: List[IndexModelField]
):
result = []
for index in left:
Expand All @@ -549,7 +545,7 @@ def list_difference(
return result

@staticmethod
def list_to_index_model(left: List["IndexModelField"]):
def list_to_index_model(left: List[IndexModelField]):
return [index.index for index in left]

@classmethod
Expand All @@ -567,12 +563,12 @@ def from_motor_index_information(cls, index_info: dict):
result.append(index_model)
return result

def same_fields(self, other: "IndexModelField"):
def same_fields(self, other: IndexModelField):
return self.fields == other.fields

@staticmethod
def find_index_with_the_same_fields(
indexes: List["IndexModelField"], index: "IndexModelField"
indexes: List[IndexModelField], index: IndexModelField
):
for i in indexes:
if i.same_fields(index):
Expand All @@ -581,7 +577,7 @@ def find_index_with_the_same_fields(

@staticmethod
def merge_indexes(
left: List["IndexModelField"], right: List["IndexModelField"]
left: List[IndexModelField], right: List[IndexModelField]
):
left_dict = {index.fields: index for index in left}
right_dict = {index.fields: index for index in right}
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "beanie"
version = "1.27.0"
description = "Asynchronous Python ODM for MongoDB"
readme = "README.md"
requires-python = ">=3.8,<4.0"
requires-python = ">=3.,<4.0"
license = { file="LICENSE" }
authors = [
{name = "Roman Right", email = "[email protected]"}
Expand Down Expand Up @@ -84,6 +84,7 @@ testpaths = [
]
filterwarnings = [
"error",

"ignore::UserWarning",
]
asyncio_mode = "auto"
Expand Down
Loading