-
Notifications
You must be signed in to change notification settings - Fork 66
Clean up rewriter code: improve efficiency, finish TODOs, and enhance documentation #2392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
…tion Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
# For other types, use regular equality | ||
try: | ||
return value1 == value2 | ||
except Exception: |
Check warning
Code scanning / CodeQL
Unreachable code Warning
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 days ago
To fix the issue, the unreachable except Exception:
block should be removed. This simplifies the code and makes it clearer, while preserving its intended functionality. The equality comparison (value1 == value2
) is robust enough for standard use cases, and the removal of the unreachable code does not affect the behavior of the function.
Changes to make:
- Remove the
try
block and theexcept Exception:
block entirely. - Replace the
try
block with a direct equality comparison (return value1 == value2
).
-
Copy modified line R50
@@ -49,7 +49,3 @@ | ||
# For other types, use regular equality | ||
try: | ||
return value1 == value2 | ||
except Exception: | ||
# If comparison fails, values are not equal | ||
return False | ||
return value1 == value2 | ||
|
❌ 2 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lintrunner found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
This PR addresses the rewriter code cleanup issue by improving efficiency, finishing important TODOs, and refactoring for better readability and documentation.
Major Changes
1. Fixed Context Passing in Condition Functions
context
parameter in condition functions was set toNone
(TODO line 173)_RewriteContext
class that provides access to model, graph/function, current node, and match information2. Simplified and Improved Binding Logic
_values_equal
function3. Efficiency Optimizations
list()
for node iteration to avoid modification-during-iteration issues4. Enhanced Documentation
pattern.py
for common rewriting scenarios5. TODO Cleanup
Example Usage
The improvements enable more powerful condition functions:
Testing
pattern_test.py
)Code Quality
The rewriter is now more efficient, better documented, and provides the proper context infrastructure that was missing for advanced pattern matching scenarios.
Fixes #2391.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.