shopify_python icon indicating copy to clipboard operation
shopify_python copied to clipboard

Linter: function parameters and line breaks

Open JasonMWhite opened this issue 7 years ago • 5 comments

When a function declaration uses type hints and needs to break across lines to stay within the character limit, we should have one parameter per line.

e.g.

def foo(self,
        bar: int,
        baz: str,
        qux: typing.Dict[str, typing.List[int]]) -> bool

    return True

and not:

def foo(self, bar: int, baz: str,
        qux: typing.Dict[str, typing.List[int]]) -> bool
    return True

As discussed https://github.com/Shopify/data_bang/pull/97#discussion_r105196063

@erikwright @honkfestival @cfournie does that about sum it up?

JasonMWhite avatar Mar 09 '17 18:03 JasonMWhite

and needs to break across lines to stay within the character limit

I might even go so far as to say when it has more than two (2) typed parameters.

honkfestival avatar Mar 09 '17 18:03 honkfestival

I'm ambivalent. @cfournie care to weigh in?

JasonMWhite avatar Mar 09 '17 18:03 JasonMWhite

When using the Python 2 function type annotations, matching names to types becomes difficult after two typed parameters and one parameter and comment per line would alleviate that difficulty.

Using the Python 3 annotations I agree more with using one-param per line after 2 types parameters after reading these examples:

def foo(self,
        bar: int,
        baz: str,
        qux: long) -> bool
    return True
def foo(self, bar: int, baz: str, qux: long) -> bool
    return True

cfournie avatar Mar 10 '17 14:03 cfournie

Those examples are pretty compelling, @cfournie .

erikwright avatar Mar 10 '17 20:03 erikwright

Then we're agreed.

JasonMWhite avatar Mar 10 '17 20:03 JasonMWhite