PyCharm extract parameter usually doesn't work: "Cannot perform refactoring using selected element(s)" -
def my_method(self): print self.my_field * 2
i'd able add parameter in other case can use different expression instead of self.my_field
, maybe self.my_other_field
or self.my_field + 1
. select self.my_field , refactor > extract > parameter. error saying "cannot perform refactoring using selected element(s)".
it should able refactor, because my_method called self.my_method()
or other_obj.my_method()
. can change these self.my_method(self.my_field)
or other_obj.my_method(other_obj.my_field)
.
in general i've been able extract parameter functionality work when expression simple, constant. if expression depending on value of existing parameter, doesn't work. guess self
special case of existing parameter. limitation of extract parameter, or doing wrong?
it seems trying refactor through renaming opposed extracting new parameter.
you note intended function of parameter extraction modify existing calls include new parameter. however, based on stated in question:
i select self.my_field
it seem either accidentally selecting statement within method, or attempting modify expression through refactoring. (or, if else, provide clarification of intended outcome?) in latter case, better suited alternative refactoring.
in general, refactoring code through extraction taking piece of code:
def my_method(): return 1 + 2
and moving innards elsewhere:
def my_method(a=1,b=2): return + b
in snippet: def my_method(self): print(self.my_field * 2)
body of method not inclusive , therefore not make sense extract statement. instead, seem wanting replace self.my_field
self.my_other_field
within declaration of my_method
. again, unclear due simplicity of example.
Comments
Post a Comment