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

Inline refactoring fails when the inlined method has type hints #440

Closed
lieryan opened this issue Nov 3, 2021 · 0 comments · Fixed by #470
Closed

Inline refactoring fails when the inlined method has type hints #440

lieryan opened this issue Nov 3, 2021 · 0 comments · Fixed by #470
Labels
affected-version:0.21 bug Unexpected or incorrect user-visible behavior inline-refactor
Milestone

Comments

@lieryan
Copy link
Member

lieryan commented Nov 3, 2021

Describe the bug

Inlining a method whose signature contains type hints fails with an exception.

Removing the type hints, the inlining works just fine.

To Reproduce
Steps to reproduce the behavior:

  1. Code before refactoring:
def foo(hello: str):
    print(hello)

foo("hello")
  1. Describe the refactoring you want to do: Inline foo

  2. Expected code after refactoring:

print("hello")
  1. Describe the error or unexpected result that you are getting
2021-11-03 15:11:44,510 AEDT - ERROR - pylsp_rope.plugin - Exception when doing workspace/executeCommand: Attribute hello: str not found
Traceback (most recent call last):
  File "/home/lieryan/Projects/pylsp-rope/pylsp_rope/plugin.py", line 128, in pylsp_execute_command
    return commands[command](workspace, **arguments[0])()
  File "/home/lieryan/Projects/pylsp-rope/pylsp_rope/plugin.py", line 152, in __call__
    rope_changeset = self.get_changes()
  File "/home/lieryan/Projects/pylsp-rope/pylsp_rope/plugin.py", line 262, in get_changes
    rope_changeset = refactoring.get_changes()
  File "/home/lieryan/.virtualenvs/pylsp-rope/lib/python3.9/site-packages/rope/refactor/inline.py", line 153, in get_changes
    self._defining_file_changes(
  File "/home/lieryan/.virtualenvs/pylsp-rope/lib/python3.9/site-packages/rope/refactor/inline.py", line 203, in _defining_file_changes
    result = move.ModuleSkipRenamer(
  File "/home/lieryan/.virtualenvs/pylsp-rope/lib/python3.9/site-packages/rope/refactor/move.py", line 842, in get_changed_module
    self.handle.occurred_outside_skip(change_collector, occurrence)
  File "/home/lieryan/.virtualenvs/pylsp-rope/lib/python3.9/site-packages/rope/refactor/inline.py", line 568, in occurred_outside_skip
    definition, returned = self.generator.get_definition(
  File "/home/lieryan/.virtualenvs/pylsp-rope/lib/python3.9/site-packages/rope/refactor/inline.py", line 409, in get_definition
    return self._calculate_definition(primary, pyname, call, host_vars, returns)
  File "/home/lieryan/.virtualenvs/pylsp-rope/lib/python3.9/site-packages/rope/refactor/inline.py", line 465, in _calculate_definition
    pyname = pymodule[name]
  File "/home/lieryan/.virtualenvs/pylsp-rope/lib/python3.9/site-packages/rope/base/pyobjects.py", line 26, in __getitem__
    return self.get_attribute(key)
  File "/home/lieryan/.virtualenvs/pylsp-rope/lib/python3.9/site-packages/rope/base/pyobjects.py", line 201, in get_attribute
    raise exceptions.AttributeNotFoundError("Attribute %s not found" % name)
rope.base.exceptions.AttributeNotFoundError: Attribute hello: str not found

Screenshots
If applicable, add screenshots to help explain your problem.

Editor information (please complete the following information):

  • Project Python version: Python 3.9
  • Rope Python version: Python 3.9
  • Rope version: 0.21.0
@lieryan lieryan added bug Unexpected or incorrect user-visible behavior inline-refactor affected-version:0.21 labels Nov 3, 2021
@lieryan lieryan changed the title Inline refactoring fails when the inlined method contains Inline refactoring fails when the inline method has type hints Nov 3, 2021
@lieryan lieryan changed the title Inline refactoring fails when the inline method has type hints Inline refactoring fails when the inlined method has type hints Nov 3, 2021
@lieryan lieryan added this to the 0.24.0 milestone Mar 23, 2022
dryobates added a commit to dryobates/rope that referenced this issue May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affected-version:0.21 bug Unexpected or incorrect user-visible behavior inline-refactor
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant