Repository navigation
Refactor star-list handling, autoimport parsing and worder naming - #965
Open
Ketankhunti wants to merge 6 commits into
Open
Ketankhunti wants to merge 6 commits into
Ketankhunti wants to merge 6 commits into
Conversation
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.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Behavior-preserving cleanups in three areas, no functional change.
rope/base/worder.py
Worder.dumb_findertofallback_finder. The old name isvague; the field holds a plain finder over the original source used
when the offset falls inside an ignored region.
rope/contrib/autoimport/parse.py
isinstanceif-chain inget_type_astwith a dispatchtable (
_NODE_TYPE_MAP). Same semantics; a new node kind now needsone table entry instead of another branch.
_names_from_importfromfromget_names_from_file. Therelative from-import loop is now a standalone generator, testable
in isolation.
rope/refactor/importutils/module_imports.py
is_str_constant,is_name_ref,is_str_assignment) for the repeatedisinstancechecks in_get_all_star_list._resolve_nameto module-level_resolve_assigned_names(it never usedself); updates the threecall sites.
_StarListCollectorto hold the pending-assignments stackand collected names;
_get_all_star_listkeeps the traversal logicwhile state lives in the new class.
Verification:
blackandisortclean on all three files.pytest ropetest/refactor/importutilstest.py— 152 passed.pytest ropetest/contrib/autoimporttest.py— 28 passed.pytest ropetest/codeanalyzetest.py— 180 passed.pytest -q— 2177 passed, 8 skipped, 5 xfailed.