Skip to content

Incorrect indentation after string literals containing escaped characters #4241

Closed

Description

@caudate-julie

Steps to reproduce:

  1. Type string with '\n' in it, press Enter.
a = '\n'

Same for double quotes.

Expected behaviour

a = '\n'
<--- cursor should be here

Actual behaviour

a = '\n'
    <--- cursor is here

Environment data

  • VS Code version: 1.30.2
  • Extension version (available under the Extensions sidebar): 2019.1.0
  • OS and version: Windows 10
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7
  • Type of virtual environment used: N/A
  • Relevant/affected Python packages and their versions: none

Logs

Console:

Starting Jedi Python language engine.

Linter 'pylint' is not installed. Please install it or select another linter".
Error: Module 'pylint' not installed.

Activity

  1. ghost added
    triage-neededNeeds assignment to the proper sub-team
    on Jan 31, 2019
  2. caudate-julie commented on Jan 31, 2019

    @caudate-julie
    Author

    I am not familiar with the code, but it may be this string:
    https://github.com/Microsoft/vscode-python/blob/c23603c9b7a3dbb805e8339a2d7cf01bb7327b34/src/client/extension.ts#L176
    since regex doesn't include end of line.

  3. changed the title [-]Incorrect indentation after string literals containing newline[/-] [+]Incorrect indentation after string literals containing escaped characters[/+] on Jan 31, 2019
  4. ghost removed
    triage-neededNeeds assignment to the proper sub-team
    on Jan 31, 2019
  5. jkyeung commented on Mar 9, 2019

    @jkyeung

    Yeah, this is really annoying. It seems like this was introduced by the "fix" for #3284.

    If I had to choose between having line continuation backslashes work properly, or backslash escapes work properly, I would choose backslash escapes in a heartbeat. Some people probably never use backslash for line continuation, while most other people probably use it very sparingly, since PEP 8 encourages implicit line continuation wherever it can be sensibly applied.

    And even if you like backslash line continuation, (1) presumably you're not going to have large sections of code riddled with them, since long lines are discouraged anyway, and (2) you have reasonable alternatives for achieving what you need. Whereas there are plenty of situations where you could be using a lot of backslash escapes (strings, regular expressions), and there is no reasonable alternative.

  6. jkyeung commented on Jun 12, 2019

    @jkyeung

    I am not familiar with the code, but it may be this string:
    https://github.com/Microsoft/vscode-python/blob/c23603c9b7a3dbb805e8339a2d7cf01bb7327b34/src/client/extension.ts#L176
    since regex doesn't include end of line.

    I'm pretty sure you've hit the nail on the head.

    It seems like such a simple and easy fix (see my comment on #5821, which perhaps should gave gone on #3915). If we are wrong about this, and it's actually more complicated, then I wish they would come out and explain why.

  7. karrtikr commented on Jun 26, 2019

    @karrtikr

    Prescribed Solution:

    There may be a more correct regex to use:

    /^(?!\s+\\)[^#\n]+\\$/

    See #5821 (comment).

    Make sure this does not break the following (from #3284):

    a = 1 + \
        <--- indent is here
  8. ericsnowcurrently commented on Jul 9, 2019

    @ericsnowcurrently

    I've verified that the following indent/dedent properly:

    a = '\n'
    # cursor here
    
    a = 1 + \
        # cursor here
  9. ghost removed on Jul 9, 2019
  10. locked as resolved and limited conversation to collaborators on Jul 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-formattingbugIssue identified by VS Code Team member as probable bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions