Skip to content

PR: Remove from ast import * from rope.base.ast#632

Closed
edreamleo wants to merge 4 commits intopython-rope:masterfrom
edreamleo:ekr-direct-ast
Closed

PR: Remove from ast import * from rope.base.ast#632
edreamleo wants to merge 4 commits intopython-rope:masterfrom
edreamleo:ekr-direct-ast

Conversation

@edreamleo
Copy link
Contributor

@edreamleo edreamleo commented Jan 1, 2023

Another attempt at removing from ast import * from rope.base.ast.

  • Add import ast whenever a module uses stdlib.ast.
  • Remove all from rope.base import ast statements.
  • Add from rope.base.ast import RopeNodeVisitor as needed,
    removing several different qualifiers from references to RopeNodeVisitor.
  • Replace ast.parse with rope.base.ast.parse.
  • Replace rope.base.ast.iter_child_nodes with ast.iter_child_nodes.
  • Replace ast.call_for_nodes with rope.base.ast.call_for_nodes.
  • Replace rope.base.ast qualifiers by ast when referring to stdlib.ast nodes.
  • In numpydocstrings.py, remove from rope.base.ast import literal_eval,
    and qualify literal_eval with ast.
  • Remove several unnecessary imports.

Summary of changes

  • ast always means stdlib.ast.
  • Use full rope.base.ast qualifications for the parse and call_for_nodes functions.
    Alternatively, we could rename ast.py to rast.py and use the rast qualifier.
  • Use no qualification for RopeNodeVisitor.

In short, all references to stdlib.ast and rope.base.ast are uniform and explicit.

Update

As noted below, three helper PR's will make most of the changes mentioned above.

@edreamleo edreamleo marked this pull request as draft January 2, 2023 10:11
@edreamleo edreamleo mentioned this pull request Jan 2, 2023
5 tasks
"""Get all the names from a given file using ast."""
try:
root_node = ast.parse(module.read_bytes())
root_node = rope.base.ast.parse(module.read_bytes())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I am aware, this should use the stdlib ast parser

Copy link
Contributor Author

@edreamleo edreamleo Jan 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bagel897 Thanks for you comment! rope.base.ast.parse wraps stdlib.ast.parse: it regularizes the source argument and catches two exceptions. These seem like reasonable things to do.

@lieryan would like to replace the one remaining call to stdlib.ast.parse with a call to rope.base.ast.parse.

I see two remaining tasks before marking this PR as ready for review:

@lieryan
Copy link
Member

lieryan commented Jan 3, 2023

Closed for same reason as #635 (comment). This is not the direction we want to take with rope.base.ast.

@lieryan lieryan closed this Jan 3, 2023
@edreamleo
Copy link
Contributor Author

edreamleo commented Jan 3, 2023

@lieryan I think we both want to move on. However, I would push back just a bit more.

I created various PRs thinking that smaller PRs would be more acceptable to you. I didn't mean to badger you. I apologize if you felt put upon.

I still think that removing from ast import * is a good idea. Most importantly, removing this statement will help mypy. But adding mypy annotations for ast.AST will likely suffice. Otoh, "wrapping" rope.base.ast doesn't seem necessary. In particular, the wildcard import does not eliminate "if" statements like typical wrappers do.

Let's put this discussion in perspective. Only three functions are involved, and I don't much care what they are called, nor do I care much what qualifiers are used, so long as Rope's code uses the qualifiers consistently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants