Repository: quantopian/zipline
File: zipline/finance/controls.py (Python)

Code before:
    def validate(self,
                 _portfolio,
                 _account,
                 _algo_datetime,
                 _algo_current_data):
        """
        Fail if the leverage is greater than the allowed leverage.
        """
        if _account.leverage > self.max_leverage:
            self.fail()


class MinLeverage(AccountControl):
    """
    AccountControl representing a limit on the minimum leverage allowed
    by the algorithm after a threshold period of time.
    """

    @expect_types(
        __funcname='MinLeverage',
        min_leverage=(int, float),
        deadline=pd.datetime
    )
    @expect_bounded(__funcname='MinLeverage', min_leverage=(0, None))
    def __init__(self, min_leverage, deadline):
        """
        min_leverage is the gross leverage in decimal form. For example,
        2, limits an algorithm to trading at minimum double the account value by
        the deadline date.
        """
        super(MinLeverage, self).__init__(min_leverage=min_leverage,
                                          deadline=deadline)
        self.min_leverage = min_leverage
        self.deadline = deadline

    def validate(self,
                 _portfolio,
                 account,
                 algo_datetime,
                 _algo_current_data):
        """
        Make validation checks if we are after the deadline.
        Fail if the leverage is less than the min leverage.
        """
        if algo_datetime > self.deadline and \
           account.leverage < self.min_leverage:
            self.fail()


Review comment (suggestion):
We generally don't put docstrings on `__init__` methods; we use the class docstring documenting the parameters to a class and describing what it's for.

Code after:

    def validate(self,
                 _portfolio,
                 _account,
                 _algo_datetime,
                 _algo_current_data):
        """
        Fail if the leverage is greater than the allowed leverage.
        """
        if _account.leverage > self.max_leverage:
            self.fail()


class MinLeverage(AccountControl):
    """AccountControl representing a limit on the minimum leverage allowed
    by the algorithm after a threshold period of time.

    Parameters
    ----------
    min_leverage : float
        The gross leverage in decimal form.
    deadline : datetime
        The date the min leverage must be achieved by.

    For example, min_leverage=2 limits an algorithm to trading at minimum
    double the account value by the deadline date.
    """

    @expect_types(
        __funcname='MinLeverage',
        min_leverage=(int, float),
        deadline=datetime
    )
    @expect_bounded(__funcname='MinLeverage', min_leverage=(0, None))
    def __init__(self, min_leverage, deadline):
        super(MinLeverage, self).__init__(min_leverage=min_leverage,
                                          deadline=deadline)
        self.min_leverage = min_leverage
        self.deadline = deadline

    def validate(self,
                 _portfolio,
                 account,
                 algo_datetime,
                 _algo_current_data):
        """
        Make validation checks if we are after the deadline.
        Fail if the leverage is less than the min leverage.
        """
        if algo_datetime > self.deadline and \
           account.leverage < self.min_leverage: