This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2015年09月21日 21:25 by serhiy.storchaka, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| rlcompleter_keyword_space.patch | serhiy.storchaka, 2015年09月21日 21:25 | review | ||
| rlcompleter_keyword_space_2.patch | serhiy.storchaka, 2015年09月22日 17:21 | review | ||
| rlcompleter_keyword_space_3.patch | serhiy.storchaka, 2015年09月24日 12:18 | review | ||
| Messages (11) | |||
|---|---|---|---|
| msg251262 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2015年09月21日 21:25 | |
Open parenthesis ('(') is appended after completed callable globals and attributes. I propose to add a space after completed keyword. In most cases a space is either required after the keyword, or recommended by PEP8. Attached patch implements this.
|
|||
| msg251282 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2015年09月22日 01:41 | |
I agree with adding a space in some cases, but not others. E.g. "pass" would only need a space if you wanted to add a comment, "return" often takes no argument, "lambda" may need an immediate colon (lambda: x). See <https://github.com/vadmium/etc/blob/0f8d459/python/pythonstartup.py#L210> for a whitelist of keywords that I thought should always have spaces, but beware this list may not be up to date (no "await" nor "async" for instance). BTW I don’t agree with the default of forcing an open bracket "(" for callables; consider decorators, subclassing, deferred function calls, etc, where that bracket may not be wanted. |
|||
| msg251332 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2015年09月22日 17:21 | |
Good catch Martin. Indeed, "pass", "break" and "continue" don't need a space, and "True", "False" and "None" need a space only in rare cases like "None in collection". Some keywords ("else", "finally", "try") need a colon. But while "return" and "lambda" not always need a space, I think that needing a space is more common case, and in any case the redundant space doesn't make a harm.
Here is revised patch that doesn't add a space in some cases and instead adds a colon in some cases.
|
|||
| msg251347 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2015年09月22日 21:44 | |
"Else" doesn’t always use a colon. Consider "1 if x else 2". Again, if Python started adding unwanted spaces and colons I imagine users could be annoyed and think Python is being too smart and complicated for its own good. But maybe see what others say. |
|||
| msg251511 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2015年09月24日 11:46 | |
I tested the patch. "wi<tab>" displays "with " (space)., but "fo<tab>" displays "for" (no space). I don't understand why. Well, it's not a big issue, anyway the patch looks good to me. IMHO you should apply it to Python 3.4-3.6 (not only 3.6). |
|||
| msg251513 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2015年09月24日 11:55 | |
Victor, maybe because "for" also stands for "format"? |
|||
| msg251514 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2015年09月24日 12:18 | |
> "Else" doesn’t always use a colon. Consider "1 if x else 2".
Good catch Martin. Unfortunately the completer doesn't take context into account. "else" with a colon is a common case, but unwanted colon could be annoyed. I agree that it would be safe to not append a colon after "else". At least unless we make the completer context aware. However I don't think that unwanted space would be so annoyed. Here is updated patch.
I see that your code does an autocompletion for module names in "import", Martin. This was my next idea. Do you want to provide a patch for including this in CPython?
> I tested the patch. "wi<tab>" displays "with " (space)., but "fo<tab>" displays "for" (no space). I don't understand why.
Because there is "format(".
> IMHO you should apply it to Python 3.4-3.6 (not only 3.6).
This is definitely a new feature. And there is a risk to break something (if standard completer is used programmatic).
|
|||
| msg251515 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2015年09月24日 12:21 | |
> This is definitely a new feature. And there is a risk to break something (if standard completer is used programmatic). Ok, it's up to you. |
|||
| msg251628 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2015年09月26日 02:24 | |
Yes I am interesting in making a patch for auto-completing module names. I’ll leave it on my to-do list, but don’t expect it overnight. :) My code does some rough parsing of Python syntax, but maybe that is not needed for "import x", though it might be needed to support module attributes for "from x import y". |
|||
| msg251698 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2015年09月27日 10:44 | |
New changeset f64ec4aac935 by Serhiy Storchaka in branch 'default': Issue #25209: rlcomplete now can add a space or a colon after completed keyword. https://hg.python.org/cpython/rev/f64ec4aac935 |
|||
| msg251700 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2015年09月27日 10:47 | |
Thank you for your review Martin. Hope to see your patch for completing import statement. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:21 | admin | set | github: 69396 |
| 2015年09月27日 10:47:57 | serhiy.storchaka | set | status: open -> closed messages: + msg251700 assignee: serhiy.storchaka resolution: fixed stage: patch review -> resolved |
| 2015年09月27日 10:44:55 | python-dev | set | nosy:
+ python-dev messages: + msg251698 |
| 2015年09月26日 02:24:00 | martin.panter | set | messages: + msg251628 |
| 2015年09月24日 12:21:40 | vstinner | set | messages: + msg251515 |
| 2015年09月24日 12:18:36 | serhiy.storchaka | set | files:
+ rlcompleter_keyword_space_3.patch messages: + msg251514 |
| 2015年09月24日 11:55:10 | martin.panter | set | messages: + msg251513 |
| 2015年09月24日 11:46:27 | vstinner | set | nosy:
+ vstinner messages: + msg251511 |
| 2015年09月22日 21:44:08 | martin.panter | set | messages: + msg251347 |
| 2015年09月22日 17:21:21 | serhiy.storchaka | set | files:
+ rlcompleter_keyword_space_2.patch messages: + msg251332 |
| 2015年09月22日 01:41:47 | martin.panter | set | nosy:
+ martin.panter messages: + msg251282 |
| 2015年09月21日 21:25:14 | serhiy.storchaka | create | |