From ba030a66a73f048636e10e5a6520be9618677478 Mon Sep 17 00:00:00 2001 From: Tim Paine <3105306+timkpaine@users.noreply.github.com> Date: Fri, 29 Nov 2024 14:57:46 -0500 Subject: [PATCH] Pass generic aliases through as-is Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com> --- ccflow/base.py | 4 ++-- ccflow/tests/test_base.py | 4 ++++ pyproject.toml | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ccflow/base.py b/ccflow/base.py index 53231cc..2091a0f 100644 --- a/ccflow/base.py +++ b/ccflow/base.py @@ -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 @@ -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 diff --git a/ccflow/tests/test_base.py b/ccflow/tests/test_base.py index 8f0eaee..77634ee 100644 --- a/ccflow/tests/test_base.py +++ b/ccflow/tests/test_base.py @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 4745574..1d9e4ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = "OpenSource@Point72.com" }, ] @@ -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", ]