fix: don't panic on a non-generic classproperty in get_attributes - #4457
fix: don't panic on a non-generic classproperty in get_attributes#4457renz011tzar wants to merge 1 commit into
Conversation
|
Hi @renz011tzar! 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! |
get_kind_and_field_type matched `classproperty`/`cached_classproperty` on the class name alone and then unwrapped the first type argument. A class with that name but no type arguments reached the arm with empty targs, so get_attributes panicked. Move the type-argument check into the match guard so such a class falls through to the existing `_ => (None, ty)` arm instead. Fixes facebook#4453
266c222 to
417ce55
Compare
|
This pull request has been imported. If you are a Meta employee, you can view this in D114848162. (Because this pull request was imported automatically, there will not be any future comments.) |
yangdanny97
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
|
@ndmitchell merged this pull request in 1ba9829. |
Fixes #4453.
get_kind_and_field_typematchedclassproperty/cached_classpropertyon the class name alone, then unwrapped the first type argument:A class with that name but no type arguments reaches this arm with empty
targs, soget_attributespanics.Change
Per @yangdanny97's suggestion in the issue, the no-type-arguments case now behaves as
(None, ty). Rather than adding a nested match, the check moves into the match guard, so such a class simply doesn't match this arm and falls through to the existing_ => (None, ty):Testing
Adds
test_get_attributes_non_generic_classproperty, following the existingTempDir+create_query()pattern intest/query.rs. It checks out a module defining a plainclass classproperty:used as a decorator, and assertsget_attributesreturns the attribute rather than panicking.panicked at pyrefly/lib/query.rs:1147:66: called Option::unwrap() on a None value) and passes with it.cargo test -p pyrefly --lib test::query— 7 passed, 0 failed.cargo fmt --checkclean.