-
Notifications
You must be signed in to change notification settings - Fork 166
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
Remove functions in rope.base.ast that has functionally identical implementation in stdlib's ast #581
Conversation
This is a name clash with standard library's `ast.walk()`, which has a different, and incompatible interface.
These functions are no longer be necessary in supported versions of Python, as a version with equivalent functionalities are now included in stdlib `ast`.
This has been replaced with iter_child_nodes() Note that iter_child_nodes() returns an iterator while get_child_nodes() returns a List.
This is now replaced with ast.iter_fields() Note that iter_fields() returns an iterator while get_children() returns a List.
This is functionally identical to stdlib's ast.NodeVisitor
FYI, @edreamleo to simplify the discussion a bit; let's start by trying to remove unnecessary parts of These are legacy implementations which I suppose likely was written back when stdlib's ast didn't have these functionalities. There's no need for rope to maintain these in |
@lieryan Good idea. |
I just pulled master and did a trial merge into ekr-reorg3, using AttributeError: module 'rope.base.astutils' has no attribute 'call_for_nodes' I'll investigate. At worst I'll just abort the merge :-) |
The crash occurs because of this line in astutils.call_for_nodes(self.ast, search, recursive=True) I'm confused: I don't see Anyway, all unit tests pass after making these changes to
Do you have any idea what happened? |
@lieryan I like what I see at first glance. Thanks for meeting me halfway. |
Another mystery. In my original merge into ekr-reorg3 One unit tests fails after removing (as I think I should) the ====================================================== FAILURES =======================================================
____________________________________ PyCoreTest.test_syntax_errors_when_null_bytes ____________________________________
self = <ropetest.pycoretest.PyCoreTest testMethod=test_syntax_errors_when_null_bytes>
def test_syntax_errors_when_null_bytes(self):
mod = testutils.create_module(self.project, "mod")
contents = b"\n\x00\n"
file = open(mod.real_path, "wb")
file.write(contents)
file.close()
with self.assertRaises(exceptions.ModuleSyntaxError):
> self.pycore.resource_to_pyobject(mod)
ropetest\pycoretest.py:734:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
rope\base\pycore.py:141: in resource_to_pyobject
return self.module_cache.get_pymodule(resource, force_errors)
rope\base\pycore.py:262: in get_pymodule
result = pyobjectsdef.PyModule(
rope\base\pyobjectsdef.py:173: in __init__
source, node = self._init_source(pycore, source, resource)
rope\base\pyobjectsdef.py:200: in _init_source
ast_node = ast.parse(source_bytes, filename=filename)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
def parse(source, filename='<unknown>', mode='exec', *,
type_comments=False, feature_version=None):
"""
Parse the source into an AST node.
Equivalent to compile(source, filename, mode, PyCF_ONLY_AST).
Pass type_comments=True to get back type comments where the syntax allows.
"""
flags = PyCF_ONLY_AST
if type_comments:
flags |= PyCF_TYPE_COMMENTS
if isinstance(feature_version, tuple):
major, minor = feature_version # Should be a 2-tuple.
assert major == 3
feature_version = minor
elif feature_version is None:
feature_version = -1
# Else it should be an int giving the minor version for 3.x.
> return compile(source, filename, mode, flags,
_feature_version=feature_version)
E ValueError: source code string cannot contain null bytes
C:\Python\Python3.10\lib\ast.py:50: ValueError
=============================================== short test summary info ===============================================
FAILED ropetest/pycoretest.py::PyCoreTest::test_syntax_errors_when_null_bytes - ValueError: source code string cannot...
=============================== 1 failed, 1938 passed, 21 skipped, 5 xfailed in 25.60s ================================ |
Description
rope.base.ast.walk()
rope.base.ast.get_children()
rope.base.ast.get_child_nodes()
Checklist (delete if not relevant):