Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@catb0t
Last active October 3, 2020 09:37
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catb0t/bd82f7815b7e95b5dd3c3ad294f3cbbf to your computer and use it in GitHub Desktop.
Save catb0t/bd82f7815b7e95b5dd3c3ad294f3cbbf to your computer and use it in GitHub Desktop.
Strict no-Any MyPy JSON type
# modified from Original source: https://github.com/python/mypy/issues/731#issuecomment-539905783
from typing import Union, Dict, List
JSONPrimitive = Union[str, int, bool, None]
JSONType = Union[JSONPrimitive, 'JSONList', 'JSONDict']
# work around mypy#731: no recursive structural types yet
class JSONList(List[JSONType]):
pass
class JSONDict(Dict[str, JSONType]):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment