typeshed icon indicating copy to clipboard operation
typeshed copied to clipboard

Add a JSON alias

Open srittau opened this issue 3 years ago • 2 comments

Cf. python/typing#182

I have deliberately not added this to any existing stubs, since that might be disruptive and needs experimentation independent from the alias itself.

srittau avatar May 21 '22 12:05 srittau

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

github-actions[bot] avatar May 21 '22 12:05 github-actions[bot]

I don't see how this would be useful:

  • Because of invariance, a dict[str, str] is not a valid JSON. This makes JSON quite useless for argument types.
  • We don't have weak unions or AnyOf, so JSON is not good for return types: you would need to assert the structure of the JSON to get anything done.

Akuli avatar May 21 '22 19:05 Akuli

We should now be able to use a properly recursive type.

However, I share the reservations about adding this if we don't know how we'll use it. I think invariance makes it so that we can't really use this alias anywhere in typeshed.

JelleZijlstra avatar Nov 25 '22 04:11 JelleZijlstra