News for hackers. Stuff that matters.
Re:Python's Type Checking Renaissance by smlckz on Tuesday January 26, 2021 @12:19PM (#25918481)
Imagine ...

1. a -> b :: Function(a)[b]

   (a, k1=t1, k2=t2) -> b :: Function(a, k1=t1, k2=t2)[b]

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

huh!

Re:Python's Type Checking Renaissance by duckerude on Tuesday January 26, 2021 @03:08PM (#25920478)
> 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.
Re:Python's Type Checking Renaissance by throwaway894345 on Tuesday January 26, 2021 @01:16PM (#25919293)
In fairness I find (1) to even less readable than the existing Callable syntax, but yeah, it would be cool if Python could express callables with kwargs and recursive types.