Hacker News .hnnew | past | comments | ask | show | jobs | submitlogin

> 2. JSON = RecTypeVar('JSON', lambda Self: Union[None, bool, int, float, str, List[Self], Dict[str, Self]])

You don't actually need this workaround—the problem is typechecker support, not syntax. You can use strings for forward definitions, like this:

  JSON = Union[str, int, None, bool, List["JSON"], Dict[str, "JSON"]]
What happens next depends on your typechecker. Mypy says this:

  error: Cannot resolve name "JSON" (possible cyclic definition)
Pytype says this:

  Recursive type annotations not supported yet
But Pyre accepts it and correctly uses it for typechecking.


Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: