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

Pass generic aliases through as-is #13

Merged
merged 1 commit into from
Nov 29, 2024
Merged
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
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.0"
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
Loading