hypothesis-jsonschema icon indicating copy to clipboard operation
hypothesis-jsonschema copied to clipboard

Idea: detailed version-specific type annotations for `Schema`

Open Zac-HD opened this issue 4 years ago • 1 comments

I recently saw https://github.com/python/typing/issues/182#issuecomment-899624078 proposing a nice trick for type-checking JSON data, and it occured to me that this could be extended to define version-specific Schema types using TypedDict. See also https://github.com/Julian/jsonschema/issues/766 and https://github.com/Julian/jsonschema/issues/778 - if we get a working implementation, this would probably be suitable for upstreaming.

For example, this would allow for static detection of exclusiveMaximum as either bool or int | float depending on the schema draft version.

Zac-HD avatar Oct 14 '21 06:10 Zac-HD

Mypy 0.990 has native support for recursive types, so this is now possible without hacks.

Zac-HD avatar Nov 14 '22 04:11 Zac-HD