Agree, the case of (recursive) JSON data structures seems pretty common now, and often just winds-up as `Any`.

Out of curiosity, what is the undocumented feature in mypy? 

On Tue, 2021-08-10 at 18:02 -0400, Rebecca Turner wrote:
It's still worth discussing -- that issue is still open. @vanburgerberg posted a workaround that relies on an undocumented feature of mypy, so there's definitely room for better support from the type system here. In particular, recursive unions like those needed to define JSON object types would be useful for all sorts of data structures, notably binary trees!

Perhaps this thread should be renamed "Recursive types".

On Tue, Aug 10, 2021, at 5:46 PM, Jelle Zijlstra wrote:


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
Member address: jelle.zijlstra@gmail.com
_______________________________________________
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: rbt@sent.as

_______________________________________________
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: pbryan@anode.ca