Repository navigation
Fix single-member enum literal subset checks - #5264
swaminimore wants to merge 2 commits into
Conversation
|
Hi @swaminimore! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
Hi @stroxler, just following up on this PR. The CLA is signed, and the Meta Import Checks have passed. The fix includes regression tests for the single-member enum literal case and the multi-member enum compatibility boundary. Could you please take a look when you get a chance? I’m happy to address any feedback or make changes if needed. Thank you! |
stroxler
left a comment
There was a problem hiding this comment.
Thanks, this looks pretty good to me!
There's one issue: the typing spec specifically excludes Flag classes from this behavior:
https://typing.python.org/en/latest/spec/enums.html#enum-literal-expansion
We should probably cover this in a test, and make sure we exclude it in Pyrefly
Also, the next time you submit it should auto-import, which will help me merge this (unfortunately auto-import doesn't run for first-time contributions because the CLA isn't signed, so only the next update triggers it)
stroxler
left a comment
There was a problem hiding this comment.
Sorry, meant to request changes for the Flag modification
This comment has been minimized.
This comment has been minimized.
|
The Shape stubs CI check is still failing at The upstream JAX |
|
I think if you rebase (and fix the concerns above) that problem should go away. There was a bug in my initial setup for jax-pyrefly-stubs but it is fixed on trunk. I'm pretty sure the current PR is just not rebased yet |
dc8517b to
e95aa62
Compare
|
This pull request has been imported. If you are a Meta employee, you can view this in D129147679. (Because this pull request was imported automatically, there will not be any future comments.) |
|
Hi @stroxler , I've updated the PR based on your feedback and rebased it onto the latest The changes now explicitly exclude The full local validation has passed, including The updated PR has also been successfully imported. Could you please take another look and approve the pending workflows when convenient? Thank you! |
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
stroxler
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
|
This pull request has been merged in e37124c. |
Summary
Fixes #5191
When a union containing a literal of a single-member enum is normalized to the enum class, Pyrefly can incorrectly reject the resulting type against a generic type alias containing that enum literal.
This change updates subset checking to accept the enum class as compatible with its literal member when both refer to the same enum and that enum has exactly one member. Multi-member enums remain subject to the existing compatibility checks.
Regression tests cover the generic type-alias case, direct function arguments, inline enum-literal unions, and compatibility boundaries for multi-member enums.
Test Plan
cargo test -p pyrefly- passed (9,109 tests passed, 3 ignored).cargo fmt --check- passed, with warnings for nightly-only formatting options.git diff --check- passed.python3 test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema- passed.cargo clippy -p pyrefly --all-targets- completed with one warning in the existing, unrelatedpyrefly/benches/micro.rsfile.AI assistance was used during investigation, implementation, and testing. The changes were reviewed and tested locally.