Skip to content

Eliminate the clash between rope.base.ast and python's ast module #570

@edreamleo

Description

@edreamleo

See PR #579.

Background

  • rope.base.ast contains five functions: parse, walk, get_child_nodes, call_for_nodes, and get_children.
  • Calls to the parse and walk functions appear in many places throughout Rope's code.
  • Calls to the get_child_nodes, call_for_nodes, and get_children appear less frequently.
    None of these three functions appear in Python's ast module.
  • Only rope.base.ast.parse calls Python's ast.parse function.
  • No calls to Python's ast.walk function appear in Rope's code.

Proposal

It should be straightforward and safe to do the following:

  • Delete rope/base/ast.py, moving its functions to rope/base/astutils.py.
    As a happy side effect, this will eliminate from ast import * from Rope's codebase.
  • Import rope.base.astutils instead of rope.base.ast everywhere.
  • Import Python's ast module as needed, including in astutils.py.
  • Access all functions in rope.base.astutils using the astutils qualifier, except within astutils itself.

Rationale

  • ast will always mean Python's ast module.
  • It will always be clear that parse and walk refer to the functions in astutils.

Update: The new code revealed that _search_in_f_string In rope/refactor/occurrences.py calls the "real" ast.parse and ast.walk functions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions