Skip to content

Commit

Permalink
improvement: use AnyStr to keep intellisense for enums but allow forw… (
Browse files Browse the repository at this point in the history
  • Loading branch information
armandobelardo authored Mar 19, 2024
1 parent 823399c commit b16d089
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
16 changes: 16 additions & 0 deletions generators/python/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion generators/python/sdk/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.3
0.12.4
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down
2 changes: 1 addition & 1 deletion seed/python-sdk/enum/strenum/src/seed/types/color.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion seed/python-sdk/enum/strenum/src/seed/types/operand.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b16d089

Please sign in to comment.