Skip to content

Refactor star-list handling, autoimport parsing and worder naming - #965

Open
Ketankhunti wants to merge 8 commits into
python-rope:masterfrom
Ketankhunti:refactor/assignment-cleanups
Open

Ketankhunti wants to merge 8 commits into
python-rope:masterfrom
Ketankhunti:refactor/assignment-cleanups

Conversation

@Ketankhunti

@Ketankhunti Ketankhunti commented Nov 22, 2026 •

Copy link
Copy Markdown

Behavior-preserving cleanups in three areas, no functional change.

rope/base/worder.py

  • Rename Worder.dumb_finder to fallback_finder. The old name is
    vague; the field holds a plain finder over the original source used
    when the offset falls inside an ignored region.

rope/contrib/autoimport/parse.py

  • Replace the isinstance if-chain in get_type_ast with a dispatch
    table (_NODE_TYPE_MAP). Same semantics; a new node kind now needs
    one table entry instead of another branch.
  • Extract _names_from_importfrom from get_names_from_file. The
    relative from-import loop is now a standalone generator, testable
    in isolation.

rope/refactor/importutils/module_imports.py

  • Introduce explaining variables (is_str_constant, is_name_ref,
    is_str_assignment) for the repeated isinstance checks in
    _get_all_star_list.
  • Move the nested _resolve_name to module-level
    _resolve_assigned_names (it never used self); updates the three
    call sites.
  • Extract _StarListCollector to hold the pending-assignments stack
    and collected names; _get_all_star_list keeps the traversal logic
    while state lives in the new class.

Verification:

  • black and isort clean on all three files.
  • pytest ropetest/refactor/importutilstest.py — 152 passed.
  • pytest ropetest/contrib/autoimporttest.py — 28 passed.
  • pytest ropetest/codeanalyzetest.py — 180 passed.
  • Full suite pytest -q — 2177 passed, 8 skipped, 5 xfailed.

cc @lieryan — behavior-preserving cleanups, CI green, happy to split or adjust.

The old name is vague and unprofessional. The field holds a plain
finder over the original source used when the offset falls inside an
ignored region. Rename both the definition and the single use in
_context_call. No behavior change.
Replace the repeated isinstance if-chain with a small type map
iterated with isinstance. Same behavior, adding a new node kind now
means adding one table entry instead of another branch.
Move the relative from-import loop out of the main child-node loop
into its own generator. get_names_from_file keeps Assign and
def/class handling; import handling is now testable in isolation.
No behavior change.
Name the repeated isinstance checks as is_str_constant,
is_name_ref and is_str_assignment so the star-list branches read
as intent instead of type-test soup. No behavior change.
Move the nested _resolve_name out of ModuleImports._get_all_star_list
as _resolve_assigned_names. It never used self; nesting hid it from
reuse and tests. Update the three call sites. No behavior change.
Move the pending-assignments stack and collected names out of
_get_all_star_list into a small helper class with has_pending,
next_assignment, defer, defer_many and add. The method keeps the
traversal logic; state lives in the new class. No behavior change.
@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.94737% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.50%. Comparing base (ff8a306) to head (53712eb).

Files with missing lines Patch % Lines
rope/contrib/autoimport/parse.py 93.75% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #965      +/-   ##
==========================================
+ Coverage   95.44%   95.50%   +0.05%     
==========================================
  Files         134      134              
  Lines       26910    26961      +51     
==========================================
+ Hits        25685    25748      +63     
+ Misses       1225     1213      -12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Cover the extracted helper: relative submodule imports with and
without asname, underlined filtering, and the skip paths (absolute
imports, same-package imports, bare relative imports, and
process_imports=False). Raises patch coverage on parse.py.
Direct unit test with a synthetic node: a plain (non-alias) name must
pass through unchanged. Closes the last patch-coverage gap in parse.py.

This branch has not been deployed

No deployments
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.

1 participant