El mar, 10 ago 2021 a las 14:37, Artemis (< artemisdev21+python-ideas@gmail.com>) escribió:
Very often while writing web-related scripts, I have a function that either accepts or returns some arbitrary JSON data.
Sometimes I know that this will be an object, so I annotate it as `dict[str, Any]` - which isn't quite accurate, since the values can't be `Any`. Sometimes I'm feeling lazy and annotate it as `dict[str, Any]` even when it may be any other JSON type.
Very occasionally do I go to the effort of making something more accurate, maybe
JsonData = Union[dict[str, 'JsonData'], list['JsonData'], int, float, bool, None]
I think adding something like this called `Json`, `JsonData`, `JsonEncodable` or similar to `typing` or `json` would be very helpful for people working with web APIs. Perhaps a `JsonObject`/`JsonDict` aliased to `dict[JsonData]` and a `JsonArray`/`JsonList` aliased to `list[JsonData]` (like in Java) would also be helpful.
This has previously been discussed in great detail in https://github.com/python/typing/issues/182 .
_______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: jelle.zijlstra@gmail.com