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

chore: allow pydantic v2 #14

Open
wants to merge 1 commit 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
7 changes: 6 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ jobs:
fail-fast: false
matrix:
python-version: [ "3.11.x" ]
pydantic-version: [ "1.10.15", "2.7.1" ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "${{ matrix.python-version }}"
pydantic-version: "${{ matrix.pydantic-version }}"
- uses: actions/cache@v3
id: poetry-cache
with:
path: ~/.local
key: ${{ matrix.python-version }}-0
key: ${{ matrix.python-version }}{{ matrix.pydantic-version }}-0
- uses: snok/install-poetry@v1
with:
virtualenvs-create: false
Expand All @@ -57,6 +59,9 @@ jobs:
pip install -U pip
poetry install --no-interaction --no-root --with=development
if: steps.cache-venv.outputs.cache-hit != 'true'
- run: |
source .venv/bin/activate
pip install pydantic=={{ pydantic-version }}

- uses: awalsh128/cache-apt-pkgs-action@latest
with:
Expand Down
5 changes: 4 additions & 1 deletion limiters/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any, ClassVar

from pydantic import BaseModel
if pydantic.VERSION.startswith('1.'):
from pydantic import BaseModel
else:
from pydantic.v1 import BaseModel
from redis import Redis as SyncRedis
from redis.asyncio import Redis as AsyncRedis
from redis.asyncio.cluster import RedisCluster as AsyncRedisCluster
Expand Down
5 changes: 4 additions & 1 deletion limiters/semaphore.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from types import TracebackType
from typing import ClassVar

from pydantic import BaseModel, Field
if pydantic.VERSION.startswith('1.'):
from pydantic import BaseModel, Field
else:
from pydantic.v1 import BaseModel, Field
from redis.asyncio.client import Pipeline
from redis.asyncio.cluster import ClusterPipeline

Expand Down
6 changes: 4 additions & 2 deletions limiters/token_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
from types import TracebackType
from typing import ClassVar

from pydantic import BaseModel, Field

if pydantic.VERSION.startswith('1.'):
from pydantic import BaseModel, Field
else:
from pydantic.v1 import BaseModel, Field
from limiters import MaxSleepExceededError
from limiters.base import AsyncLuaScriptBase, SyncLuaScriptBase

Expand Down
454 changes: 280 additions & 174 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ packages = [

[tool.poetry.dependencies]
python = "^3.11"
pydantic = "<2"
pydantic = "<3"
redis = ">4.2"

[tool.poetry.group.development.dependencies]
Expand Down
6 changes: 5 additions & 1 deletion tests/semaphore/test_async_semaphore.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
from uuid import uuid4

import pytest
from pydantic import ValidationError

if pydantic.VERSION.startswith('1.'):
from pydantic import ValidationError
else:
from pydantic.v1 import ValidationError
from redis.asyncio.client import Monitor, Redis

from limiters import AsyncSemaphore, MaxSleepExceededError
Expand Down
6 changes: 5 additions & 1 deletion tests/token_bucket/test_async_token_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
from uuid import uuid4

import pytest
from pydantic import ValidationError

if pydantic.VERSION.startswith('1.'):
from pydantic import ValidationError
else:
from pydantic.v1 import ValidationError

from limiters import AsyncTokenBucket, MaxSleepExceededError
from tests.conftest import (
Expand Down
Loading