Fix crash on functions with complex type hints #129#156
Conversation
This commit fixes issue facebookincubator#129 where Bowler would crash when handling functions with complex type hints like typing.List[str]. Changes include: 1. Modified FunctionArgument to properly store and handle complex type annotations 2. Added comprehensive test cases for various type hint scenarios: - Basic complex types (List[str]) - Nested type hints (Dict[str, List[int]]) - Multiple type hints in same function - Modifying existing type hints The fix ensures that Bowler can now safely: - Parse functions with complex type hints - Add new arguments to functions with type hints - Modify existing type hints without crashing
|
Hi @MahmoodAbuGneam! 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! |
Fix crash on functions with complex type hints
Fixes #129
Problem
Bowler currently crashes when attempting to process functions that have complex type hints (e.g.,
typing.List[str]). The error occurs because the code attempts to access the.valueattribute of aNodeobject that represents the type hint, but complex type hints are represented as nestedNodeobjects rather than simple values.Solution
I modified how
FunctionArgumenthandles type annotations by:Changes
In
bowler/imr.py:FunctionArgument.build()to store complete annotation nodesFunctionArgument.explode()to handle all annotation typesIn
bowler/tests/query.py:List[str])Dict[str, List[int]])Testing
✅ All tests pass
✅ Code formatted with black and isort
✅ New test cases added to verify the fix
Example
Before this fix:
After this fix :