srusskih / SublimeJEDI

awesome Python autocompletion with SublimeText
MIT License
938 stars 109 forks source link

Default arguments are autocompleted with leading spaces #234

Closed vshotarov closed 6 years ago

vshotarov commented 6 years ago

So, this is not necessarily an issue, but I thought I'd flag it anyway, as I have found it problematic when working with a code base that doesn't follow PEP8.

The issue

2018-02-03_11-19-13

If there are spaces between the = character and the default value of the argument, they will be reflected in the autocompletion of the function arguments.

Potential solution

I have solved it in a local copy of the repo by just adding an .lstrip() to the default value, and I'd be happy to submit a PR, but wanted to check whether you would consider this an issue, as I understand that the problem is caused by not following PEP8.

srusskih commented 6 years ago

interesting... As a user I would like receive default values suggestions without space before regards I follow pep8 or not.

It's interesting to check, why default value contains additional space. possible reasons:

vshotarov commented 6 years ago

Yes, that's how I felt, too.

It seems to me that jedi is returning the CallSignature objects in such way, as that's how they come out from the call_signatures function, before there is any processing done to them.

I added a debug statement, while going through the .params of the CallSignature of a dummy function and they come out like so.

Jedi - Python autocompletion.sublime_jedi.utils: 2018-02-05 11:18:13,709: INFO    : arg1 ="arg 01"
Jedi - Python autocompletion.sublime_jedi.utils: 2018-02-05 11:18:13,709: INFO    : arg2   =         "arg 02"
Jedi - Python autocompletion.sublime_jedi.utils: 2018-02-05 11:18:13,709: INFO    : arg3 = "arg 03"

Here's the definition

def a(arg1 ="arg 01", 
      arg2   =         "arg 02", 
      arg3 = "arg 03"):
    pass

Then splitting after the = sign, results in the autocompletion with the leading spaces and that's why I added an .lstrip(), but I get that it's more of a workaround instead of solution.

srusskih commented 6 years ago

Yeah, Looks like for now we can use .lstrip() to fix this issue. Can I ask to create a PR ? (:

srusskih commented 6 years ago

related davidhalter/jedi/issues/1039

vshotarov commented 6 years ago

Sure thing! I'll do that this evening. Thanks for investigating further!