Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

leave function-scope imports alone #92

Open
ghost opened this issue Feb 24, 2023 · 0 comments
Open

leave function-scope imports alone #92

ghost opened this issue Feb 24, 2023 · 0 comments

Comments

@ghost
Copy link

ghost commented Feb 24, 2023

I know it's against every styleguide, but black insists on reformatting this function of mine and the result is much worse than if it would just not.

Before:

def run_json_cmd(cmd: Cmd, stderr=stderr) -> Jsonish:
    from shlex import quote
    stderr.write(" ".join(("+",) + tuple(quote(arg) for arg in cmd)))
    stderr.write("\n")

    from subprocess import check_output
    output = check_output(cmd)

    from json import loads
    return loads(output)

After:

def run_json_cmd(cmd: Cmd, stderr=stderr) -> Jsonish:
    from shlex import quote

    stderr.write(" ".join(("+",) + tuple(quote(arg) for arg in cmd)))
    stderr.write("\n")

    from subprocess import check_output

    output = check_output(cmd)

    from json import loads

    return loads(output)

P.S. This is the prelude in both cases, just in case anyone wants it:

from sys import stderr
from typing import Union, List, Dict, Tuple
Jsonish = Union[
    None, int, float, str, bool, List["Jsonish"], Dict[str, "Jsonish"]
]
Cmd = tuple[Arg, ...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants