2

我正在使用 Python 2.7 并想使用绳索(通过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 实例变量的(预期)类型是什么?

4

0 回答 0