kislyuk / argcomplete

Python and tab completion, better together.
https://kislyuk.github.io/argcomplete/
Apache License 2.0
1.41k stars 134 forks source link

`warn()` message incorrectly indented one space character #334

Closed ulken closed 3 years ago

ulken commented 3 years ago

The current implementation of warn() annoyingly indents its message by one space character.

For example, the following:

warn("Log in to X to auto-complete Ys")

renders

 Log in to X to auto-complete Ys
^ <- space character

but it should be

Log in to X to auto-complete Ys
^ <- no leading space

Why is this happening? This is due to the fact that print() (which is what warn() uses under the hood) uses space (' ') as its separator. Hence, since a newline ('\n') is printed first, a space will be inserted before the next item (the actual message) is output.

Proposed solution Simply do two print() calls. One for prepending the newline, and another for the message. The first print() doesn't even need a newline since print() automatically outputs a '\n' at the end.

In code:

def warn(*args):
    print()
    print(file=debug_stream, *args)

I'll throw together a PR, if you come to agree with this being the expected behavior.