Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I got an exception using
whereisis non-trivial code example (exception at the bottom).The problem is that not every LibCST node can be rendered on its own. Some nodes are deliberately incomplete because they rely on their parent to fill in a detail at render time. The clearest example is
Annotation:def f(x: int), the annotation renders as: intdef f() -> int, the annotation renders as-> intThe
Annotationnode itself doesn't store whether it's a:or a->— the parent (ParamvsFunctionDef) supplies that "indicator" during codegen. Rendered in isolation, there's aMaybeSentinel.DEFAULTwhere the indicator should be, and LibCST raisesCSTCodegenErrorrather than guess.The fix is simply to skip the nodes that raise an exception because they can't rendered. Given that
whereisis asking "does this node's text equal/contain the fragment?" A node that has no standalone text can never match and returning false is the right answer.