Skip to content

Commit

Permalink
add python 3.13 and jit into testing
Browse files Browse the repository at this point in the history
* add python 3.13
* turn on JIT
* update code to not raise deprecation warnings
  • Loading branch information
07pepa committed Oct 14, 2024
1 parent 3421d55 commit 9ab7ee8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
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 @@ -299,19 +295,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 @@ -347,7 +343,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 @@ -358,7 +354,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 @@ -367,7 +363,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 @@ -532,7 +528,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 @@ -541,7 +537,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 @@ -559,12 +555,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 @@ -573,7 +569,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

0 comments on commit 9ab7ee8

Please sign in to comment.