Black is a bit weird in some other ways. Like preferring " over '. He has an agenda, he's not trying to codify the de facto style :(
On 27 Nov 2019, at 15:56, Ivan Levkivskyi <levkivskyi@gmail.com> wrote:
IIRC, black actually uses the first style you mention, so maybe you should rather discuss it there first. Otherwise this will create a weird situation where one of the most popular auto-formatter formats code in violation of PEP 8.
-- Ivan
On Wed, 27 Nov 2019 at 11:42, Stefano Borini <stefano.borini@gmail.com> wrote: This may be a pet peeve of mine, but with the introduction of type hints, more and more function definitions have become longer than 80 characters. This used to seldom happen in the past. The problem, as I see it, is that there seem to be a general tendency to use this way of indenting, e.g. see (among many):
https://github.com/samuelcolvin/pydantic/blob/c71326d4a6898612597d3c647a4256...
def load_file( path: Union[str, Path], *, content_type: str = None, encoding: str = 'utf8', proto: Protocol = None, allow_pickle: bool = False, ) -> Any: path = Path(path) b = path.read_bytes() if content_type is None: if path.suffix in ('.js', '.json'): proto = Protocol.json elif path.suffix == '.pkl': proto = Protocol.pickle
This violates pep8
# Add 4 spaces (an extra level of indentation) to distinguish arguments from the rest. def long_function_name( var_one, var_two, var_three, var_four): print(var_one)
However, no coding styles tools report that. Flake8 does however report a similar error for if conditions
if path.suffix in ( '.js', '.json' ): proto = Protocol.json
x.py:20:5: E125 continuation line with same indent as next logical line
But says nothing for this monstrosity, which is the equivalent of the opening case
if path.suffix in ( '.js', '.json' ): proto = Protocol.json
It is not my intention to trigger a massive discussion. My stance is that the appropriate visual aspect of the above code should be
def load_file( path: Union[str, Path], *, content_type: str = None, encoding: str = 'utf8', proto: Protocol = None, allow_pickle: bool = False) -> Any: path = Path(path) b = path.read_bytes()
to keep a visual distinction in indentation between the argument list and the function body, as in the spirit of pep8. Regardless of the choice, I think that pep8 should be updated with the appropriate style for this specific case, and style tools should enforce this choice.
-- Kind regards,
Stefano Borini _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/XKEWGJ... Code of Conduct: http://python.org/psf/codeofconduct/
Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/TPZT2U... Code of Conduct: http://python.org/psf/codeofconduct/