Skip to content

Commit 72b4f64

Browse files
chore(deps): update minor updates (master) (#84)
* 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 <[email protected]>
1 parent 77adce2 commit 72b4f64

File tree

7 files changed

+235
-265
lines changed

7 files changed

+235
-265
lines changed

.github/workflows/ci.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ on:
2525
required: false
2626
type: string
2727
# renovate: datasource=pypi depName=poetry versioning=pep440
28-
default: "1.8.3"
28+
default: "1.8.4"
2929
ruff-version:
3030
required: false
3131
type: string
3232
# renovate: datasource=pypi depName=ruff versioning=pep440
33-
default: "0.6.4"
33+
default: "0.7.4"
3434
mypy-check-files:
3535
required: false
3636
description: extra files to check with mypy
@@ -45,7 +45,7 @@ jobs:
4545
lint:
4646
runs-on: ubuntu-24.04
4747
steps:
48-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
48+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
4949
- name: ruff format
5050
uses: chartboost/ruff-action@e18ae971ccee1b2d7bbef113930f00c670b78da4 # v1
5151
with:
@@ -72,7 +72,7 @@ jobs:
7272
ports:
7373
- 27017:27017
7474
steps:
75-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
75+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
7676
- name: "Set up environment"
7777
uses: packetcoders/action-setup-cache-python-poetry@0d0be5577b30d85f3fa2d93a4beeda149520f120 # v1.2.0
7878
with:
@@ -89,7 +89,7 @@ jobs:
8989
runs-on: ubuntu-24.04
9090
needs: [lint]
9191
steps:
92-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
92+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
9393
- name: "Set up environment"
9494
uses: packetcoders/action-setup-cache-python-poetry@0d0be5577b30d85f3fa2d93a4beeda149520f120 # v1.2.0
9595
with:
@@ -122,7 +122,7 @@ jobs:
122122
if: ${{ fromJSON(needs.check_version.outputs.should_publish) }}
123123

124124
steps:
125-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
125+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
126126
# NB: we don't actually need to install the dependencies, but if we've
127127
# gotten this far they're cached anyway
128128
- name: "Set up environment"

ampel/base/AmpelBaseModel.py

+4-20
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
# Last Modified Date: 05.01.2022
88
# Last Modified By: valery brinnel <[email protected]>
99

10-
import warnings
1110
from types import UnionType
12-
from typing import TYPE_CHECKING, Any, TypeAlias, Union, get_args, get_origin
11+
from typing import TYPE_CHECKING, Any, Union, get_args, get_origin
1312

1413
from pydantic import BaseModel
1514

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

2120
if TYPE_CHECKING:
22-
IncEx: TypeAlias = 'set[int] | set[str] | dict[int, Any] | dict[str, Any] | None'
21+
from pydantic.main import IncEx
2322

2423
NoneType = type(None)
2524

@@ -50,21 +49,6 @@ def __init_subclass__(cls, *args, **kwargs) -> None:
5049
and NoneType in get_args(v)
5150
):
5251
setattr(cls, k, None)
53-
# add generic args to defaults if missing
54-
elif (
55-
k in cls.__dict__
56-
and safe_issubclass(v, AmpelBaseModel)
57-
and v.get_model_origin() is type(cls.__dict__[k])
58-
and v.get_model_args() and not cls.__dict__[k].get_model_args()
59-
):
60-
warnings.warn(
61-
DeprecationWarning(
62-
f"field {k} declared as {v}, but default has type {type(cls.__dict__[k])}"
63-
" Adding generic args to default, but this will be an error in the future."
64-
),
65-
stacklevel=1
66-
)
67-
setattr(cls, k, v.model_validate(cls.__dict__[k].model_dump()))
6852
super().__init_subclass__(*args, **kwargs)
6953

7054
@classmethod
@@ -84,8 +68,8 @@ def get_model_keys(cls) -> set[str]:
8468
def dict(
8569
self,
8670
*,
87-
include: "IncEx" = None,
88-
exclude: "IncEx" = None,
71+
include: "IncEx | None" = None,
72+
exclude: "IncEx | None" = None,
8973
by_alias: bool = False,
9074
exclude_unset: bool = False,
9175
exclude_defaults: bool = False,

ampel/base/AmpelUnit.py

+4-20
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
# Last Modified Date: 09.01.2022
88
# Last Modified By: valery brinnel <[email protected]>
99

10-
import warnings
1110
from functools import partial
1211
from types import MemberDescriptorType, UnionType
1312
from typing import TYPE_CHECKING, Any, ClassVar, Union, get_args, get_origin
1413

1514
from pydantic import BaseModel, ValidationError, create_model
1615

17-
from ampel.base.AmpelBaseModel import AmpelBaseModel, safe_issubclass
16+
from ampel.base.AmpelBaseModel import AmpelBaseModel
1817
from ampel.secret.Secret import Secret
1918
from ampel.types import TRACELESS, Traceless
2019

@@ -72,22 +71,7 @@ def __init_subclass__(cls, *args, **kwargs) -> None:
7271
if k in cls._slot_defaults:
7372
joined_defaults[k] = cls._slot_defaults[k]
7473
continue
75-
# parameterized generic with unparameterized default
76-
if (
77-
safe_issubclass(v, AmpelBaseModel)
78-
and v.get_model_origin() is type(defs[k])
79-
and v.get_model_args() and not defs[k].get_model_args()
80-
):
81-
warnings.warn(
82-
DeprecationWarning(
83-
f"field {k} declared as {v}, but default has type {type(defs[k])}"
84-
" Adding generic args to default, but this will be an error in the future."
85-
),
86-
stacklevel=1
87-
)
88-
joined_defaults[k] = v.model_validate(defs[k].model_dump())
89-
else:
90-
joined_defaults[k] = base.__dict__[k]
74+
joined_defaults[k] = base.__dict__[k]
9175
# if None | with no default
9276
elif get_origin(v) in (Union, UnionType) and NoneType in get_args(v) and k not in joined_defaults:
9377
joined_defaults[k] = None
@@ -227,8 +211,8 @@ def _get_trace_content(self) -> dict[str, Any]:
227211
def dict(
228212
self,
229213
*,
230-
include: "IncEx" = None,
231-
exclude: "IncEx" = None,
214+
include: "IncEx | None" = None,
215+
exclude: "IncEx | None" = None,
232216
by_alias: bool = False,
233217
exclude_unset: bool = False,
234218
exclude_defaults: bool = False,

0 commit comments

Comments
 (0)