Skip to content
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

Sorting error with two shadow imports #308

Open
amyreese opened this issue Jul 1, 2024 · 0 comments
Open

Sorting error with two shadow imports #308

amyreese opened this issue Jul 1, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@amyreese
Copy link
Member

amyreese commented Jul 1, 2024

Attempting to sort the following code:

from alpha.something import something
from beta import another
from beta import another
from alpha import something

Results in the following exception when sorting:

Error sorting foo.py: 'another'
Traceback (most recent call last):
  File "/Users/amethyst/workspace/usort/usort/api.py", line 33, in usort
    new_mod = sorter.sort_module()
              ^^^^^^^^^^^^^^^^^^^^
  File "/Users/amethyst/workspace/usort/usort/sorting.py", line 307, in sort_module
    new_module = self.wrapper.visit(self.transformer)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/amethyst/workspace/usort/.venv/lib/python3.12/site-packages/libcst/metadata/wrapper.py", line 204, in visit
    return self.module.visit(visitor)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/amethyst/workspace/usort/.venv/lib/python3.12/site-packages/libcst/_nodes/module.py", line 89, in visit
    result = super(Module, self).visit(visitor)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/amethyst/workspace/usort/.venv/lib/python3.12/site-packages/libcst/_nodes/base.py", line 236, in visit
    leave_result = visitor.on_leave(self, with_updated_children)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/amethyst/workspace/usort/.venv/lib/python3.12/site-packages/libcst/_visitors.py", line 71, in on_leave
    updated_node = leave_func(original_node, updated_node)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/amethyst/workspace/usort/usort/sorting.py", line 350, in leave_Module
    sorted_body = self.sorter.find_and_sort_blocks(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/amethyst/workspace/usort/usort/sorting.py", line 280, in find_and_sort_blocks
    blocks = list(self.sortable_blocks(body))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/amethyst/workspace/usort/usort/sorting.py", line 190, in sortable_blocks
    current = self.split_inplace(current, overlap)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/amethyst/workspace/usort/usort/sorting.py", line 167, in split_inplace
    new.imported_names[key] = block.imported_names.pop(key)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'another'
@amyreese amyreese added the bug Something isn't working label Jul 1, 2024
@amyreese amyreese self-assigned this Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant