Hi there,
I love the new type system. I already use it intuitively writing Python. But I think it does not go well with the PEP8 style guide, when it comes to breaking function parameters into multiple lines. Right now PEP8 suggests something like this (please correct me if I'm wrong):
def some_example_func(app_cfg_file: str, tmpl_list_file: str = 'default_list',
style: str = '', input_env: Union[str, None] = None,
tmpl_name: Union[str, None] = None) -> list:
"""This is some example function."""
environments: list = load_yaml(app_cfg_file)['environments']
env: str = input_env or get_environment(environments)
tmpl_cfgs: list = load_templates(tmpl_list_file)
tmpl_name: str = tmpl_name or get_tmpl_cfg(env, tmpl_cfgs)['name']
tmpl_style: str = get_template_style(style)
return [env, tmpl_name, tmpl_style, tmpl_list_file]
I find that this style combined with 'typing' and 'default parameters' makes the parameter definitions of a function difficult to read. This example is not a rare case, 'typing' and 'default parameters' produce a lot of functions with multi-line parameters, since the parameter definitions become much longer.
I fiddled around with this for a while and find that the code becomes quite beautiful, consistent and readable if you apply the following style to every function that has more than one parameter:
def some_example_func(
app_cfg_file: str,
tmpl_list_file: str = 'default_list',
style: str = ''
input_env: Union[str, None] = None,
tmpl_name: Union[str, None] = None
) -> list:
"""This is some example function."""
environments: list = load_yaml(app_cfg_file)['environments']
env: str = input_env or get_environment(environments)
tmpl_cfgs: list = load_templates(tmpl_list_file)
tmpl_name: str = tmpl_name or get_tmpl_cfg(env, tmpl_cfgs)['name']
tmpl_style: str = get_template_style(style)
return [env, tmpl_name, tmpl_style, tmpl_list_file]
I guess the PEP8 section on this was not designed with 'typing' and 'default parameters' in mind. How about an update? :)
Hi there,
I love the new type system. I already use it intuitively writing Python. But I think it does not go well with the PEP8 style guide, when it comes to breaking function parameters into multiple lines. Right now PEP8 suggests something like this (please correct me if I'm wrong):
I find that this style combined with 'typing' and 'default parameters' makes the parameter definitions of a function difficult to read. This example is not a rare case, 'typing' and 'default parameters' produce a lot of functions with multi-line parameters, since the parameter definitions become much longer.
I fiddled around with this for a while and find that the code becomes quite beautiful, consistent and readable if you apply the following style to every function that has more than one parameter:
I guess the PEP8 section on this was not designed with 'typing' and 'default parameters' in mind. How about an update? :)