-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add json types to _typeshed? #5910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Cf. python/typing#182. |
I wonder if we should have a third-party module on PyPI with only useful type definitions / aliases that can be more cleanly used in user code than importing from |
No one is forced to use, but we can use it in our stubs. And it's an improvement over the status quo of just returning |
@JukkaL That's actually a good idea. Just have a |
just for reference/inspiration, there's a mindblowing and mypy-specific hack for ‘correct’ json type checking: |
Fwiw, the following appears to work as expected with Pyright currently: JsonScalar = None | int | float | bool | str
JsonObject = dict[str, "JsonScalar | JsonList | JsonObject"]
JsonList = list["JsonScalar | JsonObject | JsonList"]
Json = JsonScalar | JsonList | JsonObject I think this version allows all the possible cases and nothing else based on the conversion table here. |
See also python/typing#182 (comment) I think we can close this, since we shouldn't add anything to typeshed. I'd accept a PR adding |
As this is an issue that pops up quite often and would be useful in a few places in typeshed as well: Should we add json types to
_typeshed
? As recursive types aren't possible at the moment, I'd suggest something simple like this:This can be improved if recursive types become available and could be a useful placeholder if/when the stdlib gains a proper JSON type.
The text was updated successfully, but these errors were encountered: