Open cjolowicz opened 8 months ago
Not being able to type recursive types seems like a big regression? I thought this used to be possible in pyre. I stumbled upon this today at work and I'm surprised not more people are asking for this.
Also, is PEP 695 going to be implemented in pyre?
Pyre Bug
Bug description
This recursive type alias for JSON data does not work in pyre:
Output:
Reproduction steps
https://pyre-check.org/play?input=%23%20pyre-strict%0Afrom%20typing%20import%20TypeAlias%0A%0AJSON%3A%20TypeAlias%20%3D%20None%20%7C%20bool%20%7C%20int%20%7C%20float%20%7C%20str%20%7C%20list%5B%22JSON%22%5D%20%7C%20dict%5Bstr%2C%20%22JSON%22%5D
Alternatively:
Expected behavior
No errors
Logs
Please run your reproduction steps followed by
pyre rage > pyre_rage.log
, and upload the file here:pyre_rage.log
Additional context
This is the recommended definition from https://github.com/python/typing/issues/182#issuecomment-1320974824
The code type-checks in mypy and pytype.
Omitting the quotes makes the code pass in pyre, but results in NameError at runtime:
This NameError cannot be avoided with future annotations, because it doesn't occur in an annotation.
PEP 695 type aliases don't appear to be supported yet:
Omitting the
TypeAlias
annotation avoids the first of the errors, but not the remaining four (missing argument, incompatible parameter type).