diff --git a/generators/python/sdk/CHANGELOG.md b/generators/python/sdk/CHANGELOG.md index 3ce73c801a8..a3c6fc1e1a4 100644 --- a/generators/python/sdk/CHANGELOG.md +++ b/generators/python/sdk/CHANGELOG.md @@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.12.4] - 2024-03-19 + +- Improvement: Allow full forward compat with enums while keeping intellisense by unioning enum literals with `typing.AnyStr`. + + Before: + + ```python + Operand = typing.Union[typing.AnyStr, typing.Literal[">", "=", "less_than"]] + ``` + + After: + + ```python + Operand = typing.Literal[">", "=", "less_than"] + ``` + ## [0.12.3] - 2024-03-18 - Improvement: Allow bytes requests to take in iterators of bytes, mirroring the types allowed by HTTPX. diff --git a/generators/python/sdk/VERSION b/generators/python/sdk/VERSION index aa22d3ce39b..e01e0ddd8e8 100644 --- a/generators/python/sdk/VERSION +++ b/generators/python/sdk/VERSION @@ -1 +1 @@ -0.12.3 +0.12.4 diff --git a/generators/python/src/fern_python/codegen/ast/nodes/type_hint/type_hint.py b/generators/python/src/fern_python/codegen/ast/nodes/type_hint/type_hint.py index 14ab56c3c1e..f939d8338ab 100644 --- a/generators/python/src/fern_python/codegen/ast/nodes/type_hint/type_hint.py +++ b/generators/python/src/fern_python/codegen/ast/nodes/type_hint/type_hint.py @@ -75,6 +75,10 @@ def not_required(wrapped_type: TypeHint) -> TypeHint: type_parameters=[TypeParameter(wrapped_type)], ) + @staticmethod + def any_str() -> TypeHint: + return TypeHint(type=get_reference_to_typing_import("AnyStr")) + @staticmethod def optional(wrapped_type: TypeHint) -> TypeHint: return TypeHint( diff --git a/generators/python/src/fern_python/generators/pydantic_model/type_declaration_handler/enum_generator.py b/generators/python/src/fern_python/generators/pydantic_model/type_declaration_handler/enum_generator.py index af98b7c5405..3d7141f2018 100644 --- a/generators/python/src/fern_python/generators/pydantic_model/type_declaration_handler/enum_generator.py +++ b/generators/python/src/fern_python/generators/pydantic_model/type_declaration_handler/enum_generator.py @@ -33,8 +33,11 @@ def generate(self) -> None: if self._use_str_enums: self._source_file.add_declaration( AST.TypeAliasDeclaration( - type_hint=AST.TypeHint.literal( - AST.Expression(", ".join(map(lambda v: f'"{v.name.wire_value}"', self._enum.values))) + type_hint=AST.TypeHint.union( + AST.TypeHint.any_str(), + AST.TypeHint.literal( + AST.Expression(", ".join(map(lambda v: f'"{v.name.wire_value}"', self._enum.values))) + ), ), name=self._name.name.pascal_case.safe_name, ), diff --git a/seed/python-sdk/enum/strenum/src/seed/types/color.py b/seed/python-sdk/enum/strenum/src/seed/types/color.py index 9186d24e048..672574fb1b6 100644 --- a/seed/python-sdk/enum/strenum/src/seed/types/color.py +++ b/seed/python-sdk/enum/strenum/src/seed/types/color.py @@ -2,4 +2,4 @@ import typing -Color = typing.Literal["red", "blue"] +Color = typing.Union[typing.AnyStr, typing.Literal["red", "blue"]] diff --git a/seed/python-sdk/enum/strenum/src/seed/types/operand.py b/seed/python-sdk/enum/strenum/src/seed/types/operand.py index 46fb5ed3485..df5b5b60de1 100644 --- a/seed/python-sdk/enum/strenum/src/seed/types/operand.py +++ b/seed/python-sdk/enum/strenum/src/seed/types/operand.py @@ -2,4 +2,4 @@ import typing -Operand = typing.Literal[">", "=", "less_than"] +Operand = typing.Union[typing.AnyStr, typing.Literal[">", "=", "less_than"]]