Skip to content

Commit

Permalink
Merge pull request #13 from timkpaine/tkp/genericalias
Browse files Browse the repository at this point in the history
Pass generic aliases through as-is
  • Loading branch information
timkpaine authored Nov 29, 2024
2 parents 3eea549 + ba030a6 commit fde5693
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ccflow/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pathlib
import platform
import typing
from types import MappingProxyType
from types import GenericAlias, MappingProxyType
from typing import Any, Callable, ClassVar, Dict, Generic, List, Optional, Tuple, Type, TypeVar, get_args, get_origin

import typing_extensions
Expand Down Expand Up @@ -129,7 +129,7 @@ def _adjust_annotations(annotation):
args = get_args(annotation)
else:
args = get_args(annotation)
if inspect.isclass(annotation) and issubclass(annotation, PydanticBaseModel):
if isinstance(annotation, GenericAlias) or (inspect.isclass(annotation) and issubclass(annotation, PydanticBaseModel)):
return SerializeAsAny[annotation]
elif origin and args:
# Filter out typing.Type and generic types
Expand Down
4 changes: 4 additions & 0 deletions ccflow/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class CopyModel(BaseModel):
x: str


class GenericAliasAdjust(BaseModel):
x: list[str]


class TestBaseModel(TestCase):
def test_extra_fields(self):
self.assertRaises(ValidationError, MyTestModel, a="foo", b=0.0, extra=None)
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description = "Composable Configuration Flow"
version = "0.3.1"
readme = "README.md"
license = { file = "LICENSE" }
requires-python = ">=3.8"
requires-python = ">=3.9"
authors = [
{ name = "Point72", email = "[email protected]" },
]
Expand All @@ -23,11 +23,11 @@ classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"License :: OSI Approved :: Apache Software License",
]

Expand Down

0 comments on commit fde5693

Please sign in to comment.