Closed henrylhtsang closed 5 months ago
cc @MaggieMoss
Does the following work for you?
from typing import *
x: Optional[int | str] = None
It does on the latest version of Pyre. If this doesn't work, we may need to do an upgrade.
@migeed-z not suer if I understand correctly, I thought it got an error since int | str
is a new syntax for python 3.10 only? And that part code: Optional[int | str] = None
is in pyre code
To verify if the error is due to unsupported syntax, could you doublecheck if the code above type check for you?
@migeed-z interesting, I tested in https://github.com/pytorch/torchrec/actions/runs/8807458504/job/24174554261
pyre is python 3.8 with "version": "0.0.101703592829", but does not see an error.
Did you test that one small repro or the entire code?
@migeed-z I added that code snippet to a single unit test, and then run the pyre github action with it.
This one:
from typing import *
x: Optional[int | str] = None
I see. Thanks for the information. Are we able to run on the same version of the original code though? because the error message you have originally suggests the syntax is not supported, so I wonder if there is a variation between both versions or if your original code has a different issue.
On Python < 3.10 the source file must start with from __future__ import annotations
to be able to use PEP 604 syntax.
On Python < 3.10, there should be two tests:
from __future__ import annotations
should pass if it uses PEP 604 syntax.from __future__ import annotations
should fail if it uses PEP 604 syntax.Closing the loop on this: I backed all these out to only use Union
.
We cannot make use of from __future__ import annotations
because this code is using the types at runtime (via dataclasses_json
.
I've increased the number of tests we run in github CI to make this kind of error less likely (we have to rely on github CI because internally we only use 3.10, so we tend to not notice 3.8/3.9 issues right away)
Pyre Bug
Bug description
When using python 3.8 and 3.9 with pyre, getting the following error due to
code: Optional[int | str] = None
https://github.com/facebook/pyre-check/blob/main/client/language_server/protocol.py#L365Reproduction steps Enter steps to reproduce the behavior. Follow https://github.com/pytorch/torchrec/blob/main/.github/workflows/pyre.yml to run pyre check with "version": "0.0.101711451648"
Expected behavior It should run.
The syntax is only created in python 3.10 and after. https://stackoverflow.com/questions/76712720/typeerror-unsupported-operand-types-for-type-and-nonetype
Logs