如何让绳子意识到实例属性属于某种类型

时间:2015-08-04 08:36:05

标签: python automated-refactoring rope

我正在使用Python 2.7,并希望使用rope(在vim中通过python-mode)进行一些重构。

我有一个包含我想要重构的方法的类,另一个类包含一个包含第一个类实例的实例属性。

假设我想在以下示例中更改Car.get_n_wheels()的名称:

class Car(object):
    def __init__(self, n_wheels):
        self._n_wheels = n_wheels

    def get_n_wheels(self):
        return self._n_wheels


class Garage(object):

    def __init__(self, car):
        self._car = car       # with this line print_n_wheels is not refactored
        # self._car = Car(4)  # with this line print_n_wheels is refactored

    def print_n_wheels(self):
        ''''getter'''
        print self._car.get_n_wheels()

只有当我通过创建新的Car对象明确强制_car是汽车时,才会更改最后一行,但我想将完成的汽车对象交给构造函数。

有没有办法告诉rope什么是实例变量的(预期)类型?

0 个答案:

没有答案