-
Notifications
You must be signed in to change notification settings - Fork 192
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
Add helper functions for common ways of filtering nodes #1137
Add helper functions for common ways of filtering nodes #1137
Conversation
…so that other libraries may provide their own custom representation of LibCST graphs.
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.
High level making these public makes sense, but:
- it's worth extracting
_is_syntax
and_is_whitespace
into their own public functions (with docstrings and tests) - move all of these under
libcst.helpers
, please
… docstrings & tests), in libcst.helpers
Following functions - with docstrings and tests - have been created in
All above functions are now part the Sphinx Helpers doc.
|
(Please check the tests ; I was not really sure how to properly cover use cases, so do tell if work needs to be done there) |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1137 +/- ##
==========================================
+ Coverage 91.12% 91.15% +0.02%
==========================================
Files 256 258 +2
Lines 26567 26689 +122
==========================================
+ Hits 24210 24328 +118
- Misses 2357 2361 +4 ☔ View full report in Codecov by Sentry. |
Gotta fix the type errors and this is good to go. |
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.
Thank you!
Summary
Currently, the way to print out the CST is using
libcst.tool.dump
.There are many useful inner functions in
libcst.tool
which could be used by 3rd parties to provide their own custom representation of LibCST graphs.The goal of this PR is to expose some of these functions: functions which help to filter all the non-relevant data from the CST.
Changes
Following functions have been created in
libcst.helpers
:get_node_fields
is_whitespace_node_field
is_syntax_node_field
get_field_default_value
is_default_node_field
filter_node_fields
And
libcst.tool.dump
now usesfilter_node_fields
.Test Plan
Parse a simple CST, then check CST-nodes have their fields properly filtered when using filter functions.