-
Notifications
You must be signed in to change notification settings - Fork 87
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
Make MaybeTree
the main Python AST entrypoint for constructing the syntax tree
#3550
Conversation
nodes.add(node) | ||
count += 1 | ||
assert len(nodes) == count | ||
|
||
|
||
def test_parses_incorrectly_indented_code() -> None: |
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.
Test is removed as we now always parse the source code before constructing the tree
✅ 175/175 passed, 1 flaky, 16 skipped, 3h57m54s total Flaky tests:
Running from acceptance #8104 |
@@ -290,16 +290,3 @@ def test_lints_complex_dbutils_notebook_run() -> None: | |||
linter = DbutilsPyLinter(CurrentSessionState()) | |||
advices = list(linter.lint(source)) | |||
assert not advices | |||
|
|||
|
|||
def test_tree_maybe_parse_fails_on_jupyter_magic() -> None: |
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.
Test is moved to test_python_ast.py
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.
LGTM, nothing that prevents merging. A few comments, but more food for thought and definitely not blocking.
def _walk(cls, node: NodeNG) -> Iterable[NodeNG]: | ||
def _walk(self, node: NodeNG) -> Iterable[NodeNG]: | ||
yield node | ||
for child in node.get_children(): | ||
yield from cls._walk(child) | ||
yield from self._walk(child) |
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.
I think this can remain a class method?
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.
yes, maybe, it does not make sense to me though. This is a protected method thus it should not be reached from outside the class, thus losing the benefit of calling the method without initializing the class, like Tree._walk
. Furthermore, it is only called from the Tree.walk
method, which is a regular method already, so why should this not be a regular method?
Changes
Make
MaybeTree
the main Python AST entrypoint for constructing the syntax tree:@classmethod
s and@staticmethod
s that construct aMaybeTree
from theTree
to theMaybeTree
class as this uses the@classmethod
properly by returning the initialization of the forcls
argument@classmethod
that normalizes the source code before parsing the only entrypoint by removing the other@classmethod
that does not normalize the source code before parsing to enforce normalization (and resolve the linked issues below)normalized_parse
tofrom_source_code
to match the commonly used naming forclassmethod
s within UCXMaybeTree
's methodswalk
andfirst_statement
as those are repetitions fromTree
's methodsLinked issues
Resolves #3457
Resolves #3213
Functionality
Tests