Menu

#1187 Renaming variables changes strings as well

open
nobody
5
2010-07-13
2010-07-13
---
No

Short example code:

def test(self, str):
txt = "str"
return str

Right-clicking on str variable on the first line -> refactor -> rename changes also the second line to txt = "newvar".

Discussion

  • Anonymous

    Anonymous - 2011-06-02

    I would like to extend the example:

    @decorate(name="name")
    def func():
    name = "name"
    print(name)

    Renaming the 'name' variable inside func() to 'name2' would result in the following code:

    @decorate(name2="name2")
    def func():
    name2 = "name2"
    print(name2)

     
  • sirjis

    sirjis - 2012-05-23

    This is sometimes what you want, though:

    def func(newval):
    if newval >= 10:
    raise ValueError("newval must be less than 10")

     
  • Piotr Dobrogost

    Piotr Dobrogost - 2012-05-23

    @sirjis

    In your example you use the variable being refactored whereas in the original it's part of string literal which is different type of entity.