Skip to content

Commit efc1c7b

Browse files
authored
Advanced type hinting support (#102)
1 parent 8171049 commit efc1c7b

File tree

6 files changed

+589
-835
lines changed

6 files changed

+589
-835
lines changed

README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,20 @@ The default data converter supports converting multiple types including:
187187
* `None`
188188
* `bytes`
189189
* `google.protobuf.message.Message` - As JSON when encoding, but has ability to decode binary proto from other languages
190-
* Anything that [`json.dump`](https://docs.python.org/3/library/json.html#json.dump) supports
191-
192-
As a special case in the default converter, [data classes](https://docs.python.org/3/library/dataclasses.html) are
193-
automatically [converted to dictionaries](https://docs.python.org/3/library/dataclasses.html#dataclasses.asdict) before
194-
encoding as JSON. Since Python is a dynamic language, when decoding via
195-
[`json.load`](https://docs.python.org/3/library/json.html#json.load), the type is not known at runtime so, for example,
196-
a JSON object will be a `dict`. As a special case, if the parameter type hint is a data class for a JSON payload, it is
197-
decoded into an instance of that data class (properly recursing into child data classes). Currently this capability does
198-
not extend to any other type hints that may wrap a data class like `Optional`, `List`, etc. This support is planned.
190+
* Anything that can be converted to JSON including:
191+
* Anything that [`json.dump`](https://docs.python.org/3/library/json.html#json.dump) supports natively
192+
* [dataclasses](https://docs.python.org/3/library/dataclasses.html)
193+
* Iterables including ones JSON dump may not support by default, e.g. `set`
194+
* Any class with a `dict()` method and a static `parse_obj()` method, e.g.
195+
[Pydantic models](https://pydantic-docs.helpmanual.io/usage/models)
196+
* [IntEnum](https://docs.python.org/3/library/enum.html) based enumerates
197+
198+
For converting from JSON, the workflow/activity type hint is taken into account to convert to the proper type. Care has
199+
been taken to support all common typings including `Optional`, `Union`, all forms of iterables and mappings, `NewType`,
200+
etc in addition to the regular JSON values mentioned before.
201+
202+
Users are strongly encouraged to use a single `dataclass` for parameter and return types so fields with defaults can be
203+
easily added without breaking compatibility.
199204

200205
### Workers
201206

0 commit comments

Comments
 (0)