Skip to content

Commit

Permalink
Add python 3.13 to CI and pypi (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
zmievsa authored Oct 25, 2024
1 parent 0dda043 commit 1582f4f
Show file tree
Hide file tree
Showing 9 changed files with 297 additions and 224 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
python-version: "3.11"
- os: ubuntu-latest
python-version: "3.12"
- os: ubuntu-latest
python-version: "3.13"
- os: windows-latest
python-version: "3.10"
- os: macos-latest
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/daily_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ jobs:
update-dependencies-and-test:
name: Update dependencies and run tests
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-python-uv
with:
python-version: ${{ matrix.python-version }}
- run: uv sync --refresh --all-extras --dev --upgrade
- run: pytest .
- uses: jakebailey/pyright-action@v1
with:
pylance-version: latest-release

notify-on-failure:
name: Notify on failure
Expand Down
2 changes: 1 addition & 1 deletion cadwyn/schema_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ def __init__(self, model_bundle: _ModelBundle) -> None:

def __getitem__(self, model: type[_T_ANY_MODEL], /) -> type[_T_ANY_MODEL]:
if not isinstance(model, type) or not issubclass(model, BaseModel | Enum) or model in (BaseModel, RootModel):
return model # pyright: ignore[reportReturnType]
return model
model = _unwrap_model(model)

if model in self.concrete_models:
Expand Down
2 changes: 2 additions & 0 deletions cadwyn/structure/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ def _validate_subclass(cls):
"instructions_to_migrate_to_previous_version",
"__module__",
"__doc__",
"__firstlineno__",
"__static_attributes__",
}:
raise CadwynStructureError(
f"Found: '{attr_name}' attribute of type '{type(attr_value)}' in '{cls.__name__}'."
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "cadwyn"
version = "4.4.0"
version = "4.4.1"
description = "Production-ready community-driven modern Stripe-like API versioning in FastAPI"
authors = [{ name = "Stanislav Zmiev", email = "[email protected]" }]
license = "MIT"
Expand All @@ -20,6 +20,7 @@ keywords = [
"python310",
"python311",
"python312",
"python313",
]
classifiers = [
"Intended Audience :: Information Technology",
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def version_change(
**body_items: Any,
):
return type(VersionChange)(
"MyVersionChange",
"MyVersionChange", # pyright: ignore[reportCallIssue]
(VersionChange,),
{
"description": "",
Expand Down
15 changes: 10 additions & 5 deletions tests/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ def test__render_model__with_weird_types():
)
# TODO: sobolevn has created a tool for doing such nocovers in a better manner.
# hopefully someday we will switch to it.
if sys.version_info >= (3, 11): # pragma: no cover # We cover this in CI
if sys.version_info >= (3, 11):
rendered_lambda = "lambda: 83"
else: # pragma: no cover # We cover this in CI
else:
rendered_lambda = "lambda : 83"

if sys.version_info >= (3, 13):
rend_ann = "typing.Annotated"
else:
rend_ann = "Annotated"

# TODO: As you see, we do not rename bases correctly in render. We gotta fix it some day...
assert code(result) == code(
f'''
Expand All @@ -32,11 +37,11 @@ class ModelWithWeirdFields(A):
foo: dict = Field(default={{'a': 'b'}})
bar: list[int] = Field(default_factory=my_default_factory)
baz: typing.Literal[MyEnum.foo] = Field()
saz: Annotated[str, StringConstraints(to_upper=True)] = Field()
laz: Annotated[int, None, Interval(gt=12, ge=None, lt=None, le=None), None] = Field()
saz: {rend_ann}[str, StringConstraints(to_upper=True)] = Field()
laz: {rend_ann}[int, None, Interval(gt=12, ge=None, lt=None, le=None), None] = Field()
taz: typing.Union[int, str, None] = Field(default_factory={rendered_lambda})
naz: list[int] = Field(default=[1, 2, 3])
gaz: Annotated[bytes, Strict(strict=True), Len(min_length=0, max_length=None)] = Field(min_length=3, title='Hewwo')
gaz: {rend_ann}[bytes, Strict(strict=True), Len(min_length=0, max_length=None)] = Field(min_length=3, title='Hewwo')
'''
)

Expand Down
16 changes: 11 additions & 5 deletions tests/test_schema_generation/test_schema_validator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import re

import pytest
from pydantic import BaseModel, field_validator, model_validator, root_validator, validator
from pydantic import (
BaseModel,
field_validator,
model_validator,
root_validator, # pyright: ignore[reportDeprecated]
validator, # pyright: ignore[reportDeprecated]
)

from cadwyn.exceptions import InvalidGenerationInstructionError
from cadwyn.structure import schema
Expand Down Expand Up @@ -58,12 +64,12 @@ def test__schema_validator_existed__with_deprecated_validators(
):
with pytest.warns(DeprecationWarning):

@root_validator(pre=True)
@root_validator(pre=True) # pyright: ignore[reportDeprecated]
def hewwo(cls, values):
values["foo"] += "_root"
return values

@validator("foo")
@validator("foo") # pyright: ignore[reportDeprecated]
def dawkness(cls, value):
return value + "_field"

Expand Down Expand Up @@ -178,7 +184,7 @@ class SchemaWithOneStrField(BaseModel):

with pytest.warns(DeprecationWarning):

@validator("bar")
@validator("bar") # pyright: ignore[reportDeprecated]
def validate_bar(cls, value):
raise NotImplementedError

Expand All @@ -191,7 +197,7 @@ def validate_foo(cls, value):
class ExpectedSchema(BaseModel):
bar: str

@validator("bar")
@validator("bar") # pyright: ignore[reportDeprecated]
def validate_bar(cls, value):
raise NotImplementedError

Expand Down
Loading

0 comments on commit 1582f4f

Please sign in to comment.