Skip to content

Commit

Permalink
chore(deps): update minor updates (master) (#84)
Browse files Browse the repository at this point in the history
* chore(deps): update minor updates

* chore: use annotations from pydantic for overrides

IncEx is public as of pydantic 2.10

* fix: remove workarounds for generic validation

Obviated by pydantic/pydantic#10666, which
does the Right Thing with instances of unparameterized generics.

* chore(deps): remove ruff from poetry env

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jakob van Santen <jvansanten@gmail.com>
  • Loading branch information
renovate[bot] and jvansanten authored Nov 22, 2024
1 parent 77adce2 commit 72b4f64
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 265 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ on:
required: false
type: string
# renovate: datasource=pypi depName=poetry versioning=pep440
default: "1.8.3"
default: "1.8.4"
ruff-version:
required: false
type: string
# renovate: datasource=pypi depName=ruff versioning=pep440
default: "0.6.4"
default: "0.7.4"
mypy-check-files:
required: false
description: extra files to check with mypy
Expand All @@ -45,7 +45,7 @@ jobs:
lint:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: ruff format
uses: chartboost/ruff-action@e18ae971ccee1b2d7bbef113930f00c670b78da4 # v1
with:
Expand All @@ -72,7 +72,7 @@ jobs:
ports:
- 27017:27017
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: "Set up environment"
uses: packetcoders/action-setup-cache-python-poetry@0d0be5577b30d85f3fa2d93a4beeda149520f120 # v1.2.0
with:
Expand All @@ -89,7 +89,7 @@ jobs:
runs-on: ubuntu-24.04
needs: [lint]
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: "Set up environment"
uses: packetcoders/action-setup-cache-python-poetry@0d0be5577b30d85f3fa2d93a4beeda149520f120 # v1.2.0
with:
Expand Down Expand Up @@ -122,7 +122,7 @@ jobs:
if: ${{ fromJSON(needs.check_version.outputs.should_publish) }}

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
# NB: we don't actually need to install the dependencies, but if we've
# gotten this far they're cached anyway
- name: "Set up environment"
Expand Down
24 changes: 4 additions & 20 deletions ampel/base/AmpelBaseModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
# Last Modified Date: 05.01.2022
# Last Modified By: valery brinnel <firstname.lastname@gmail.com>

import warnings
from types import UnionType
from typing import TYPE_CHECKING, Any, TypeAlias, Union, get_args, get_origin
from typing import TYPE_CHECKING, Any, Union, get_args, get_origin

from pydantic import BaseModel

Expand All @@ -19,7 +18,7 @@
from pydantic._internal._generics import get_origin as _internal_get_origin

if TYPE_CHECKING:
IncEx: TypeAlias = 'set[int] | set[str] | dict[int, Any] | dict[str, Any] | None'
from pydantic.main import IncEx

NoneType = type(None)

Expand Down Expand Up @@ -50,21 +49,6 @@ def __init_subclass__(cls, *args, **kwargs) -> None:
and NoneType in get_args(v)
):
setattr(cls, k, None)
# add generic args to defaults if missing
elif (
k in cls.__dict__
and safe_issubclass(v, AmpelBaseModel)
and v.get_model_origin() is type(cls.__dict__[k])
and v.get_model_args() and not cls.__dict__[k].get_model_args()
):
warnings.warn(
DeprecationWarning(
f"field {k} declared as {v}, but default has type {type(cls.__dict__[k])}"
" Adding generic args to default, but this will be an error in the future."
),
stacklevel=1
)
setattr(cls, k, v.model_validate(cls.__dict__[k].model_dump()))
super().__init_subclass__(*args, **kwargs)

@classmethod
Expand All @@ -84,8 +68,8 @@ def get_model_keys(cls) -> set[str]:
def dict(
self,
*,
include: "IncEx" = None,
exclude: "IncEx" = None,
include: "IncEx | None" = None,
exclude: "IncEx | None" = None,
by_alias: bool = False,
exclude_unset: bool = False,
exclude_defaults: bool = False,
Expand Down
24 changes: 4 additions & 20 deletions ampel/base/AmpelUnit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
# Last Modified Date: 09.01.2022
# Last Modified By: valery brinnel <firstname.lastname@gmail.com>

import warnings
from functools import partial
from types import MemberDescriptorType, UnionType
from typing import TYPE_CHECKING, Any, ClassVar, Union, get_args, get_origin

from pydantic import BaseModel, ValidationError, create_model

from ampel.base.AmpelBaseModel import AmpelBaseModel, safe_issubclass
from ampel.base.AmpelBaseModel import AmpelBaseModel
from ampel.secret.Secret import Secret
from ampel.types import TRACELESS, Traceless

Expand Down Expand Up @@ -72,22 +71,7 @@ def __init_subclass__(cls, *args, **kwargs) -> None:
if k in cls._slot_defaults:
joined_defaults[k] = cls._slot_defaults[k]
continue
# parameterized generic with unparameterized default
if (
safe_issubclass(v, AmpelBaseModel)
and v.get_model_origin() is type(defs[k])
and v.get_model_args() and not defs[k].get_model_args()
):
warnings.warn(
DeprecationWarning(
f"field {k} declared as {v}, but default has type {type(defs[k])}"
" Adding generic args to default, but this will be an error in the future."
),
stacklevel=1
)
joined_defaults[k] = v.model_validate(defs[k].model_dump())
else:
joined_defaults[k] = base.__dict__[k]
joined_defaults[k] = base.__dict__[k]
# if None | with no default
elif get_origin(v) in (Union, UnionType) and NoneType in get_args(v) and k not in joined_defaults:
joined_defaults[k] = None
Expand Down Expand Up @@ -227,8 +211,8 @@ def _get_trace_content(self) -> dict[str, Any]:
def dict(
self,
*,
include: "IncEx" = None,
exclude: "IncEx" = None,
include: "IncEx | None" = None,
exclude: "IncEx | None" = None,
by_alias: bool = False,
exclude_unset: bool = False,
exclude_defaults: bool = False,
Expand Down
Loading

0 comments on commit 72b4f64

Please sign in to comment.