From 8becd144bc0edece8b5da0f6eb6a6d101a2c3c50 Mon Sep 17 00:00:00 2001 From: 07pepa <9963200+07pepa@users.noreply.github.com> Date: Fri, 11 Oct 2024 09:26:31 +0200 Subject: [PATCH] add python 3.13 and jit into testing * add python 3.13 * turn on JIT * update code to not raise deprecation warnings --- .github/workflows/github-actions-tests.yml | 6 ++-- beanie/odm/fields.py | 34 ++++++++++------------ pyproject.toml | 1 + 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/.github/workflows/github-actions-tests.yml b/.github/workflows/github-actions-tests.yml index 25cab9c6..1c9bbec7 100644 --- a/.github/workflows/github-actions-tests.yml +++ b/.github/workflows/github-actions-tests.yml @@ -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 @@ -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 \ No newline at end of file diff --git a/beanie/odm/fields.py b/beanie/odm/fields.py index c93cc892..1ff22aca 100644 --- a/beanie/odm/fields.py +++ b/beanie/odm/fields.py @@ -1,5 +1,6 @@ +from __future__ import annotations + import asyncio -import sys from collections import OrderedDict from dataclasses import dataclass from enum import Enum @@ -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 ( @@ -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 @@ -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: @@ -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()) @@ -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") @@ -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: @@ -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 @@ -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): @@ -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} diff --git a/pyproject.toml b/pyproject.toml index 3cfd3aeb..151184fb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,6 +84,7 @@ testpaths = [ ] filterwarnings = [ "error", + "ignore::DeprecationWarning", "ignore::UserWarning", ] asyncio_mode = "auto"