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

patchedast doesn't consider the annotation of arguments #802

Open
v587su opened this issue Oct 24, 2024 · 0 comments
Open

patchedast doesn't consider the annotation of arguments #802

v587su opened this issue Oct 24, 2024 · 0 comments
Labels
bug Unexpected or incorrect user-visible behavior

Comments

@v587su
Copy link

v587su commented Oct 24, 2024

The following code will trigger an AttributeError:

source_code = dedent("""
def foo(l: list):
    pass
""")

finder = RawSimilarFinder(source_code)
pattern = "${a}"
print(list(finder.get_matches(pattern)))
Traceback (most recent call last):
  File "/workspace/test.py", line 11, in <module>
    print(list(finder.get_matches(pattern)))
  File "/usr/local/lib/python3.10/dist-packages/rope/refactor/similarfinder.py", line 109, in get_matches
    match_start, match_end = match.get_region()
  File "/usr/local/lib/python3.10/dist-packages/rope/refactor/similarfinder.py", line 259, in get_region
    return self.ast.region
AttributeError: 'Name' object has no attribute 'region'

This is because line 632 in rope.refactor.patchedast doesn't consider the annotation of arg.

    def _arg(self, node):
        self._handle(node, [node.arg])

Change it to the following code can fix the bug

    def _arg(self, node):
        if node.annotation:
            self._handle(node, [node.arg, ":", node.annotation])
        else:
            self._handle(node, [node.arg])
@v587su v587su added the bug Unexpected or incorrect user-visible behavior label Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected or incorrect user-visible behavior
Projects
None yet
Development

No branches or pull requests

1 participant