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

IndendationError from multi-line indented statements #90249

Closed
ucodery mannequin opened this issue Dec 15, 2021 · 7 comments
Closed

IndendationError from multi-line indented statements #90249

ucodery mannequin opened this issue Dec 15, 2021 · 7 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@ucodery
Copy link
Mannequin

ucodery mannequin commented Dec 15, 2021

BPO 46091
Nosy @gvanrossum, @lysnikolaou, @pablogsal, @ucodery
PRs
  • bpo-46091: Correctly calculate indentation levels for whitespace lines with continuation characters #30130
  • [3.10] bpo-46091: Correctly calculate indentation levels for whitespace lines with continuation characters (GH-30130). #30898
  • [3.9] bpo-46091: Correctly calculate indentation levels for whitespace lines with continuation characters (GH-30130). (GH-30898) #30899
  • Files
  • nodent.py: example program where every indented line also uses ''
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2022-01-25.22:38:52.006>
    created_at = <Date 2021-12-15.23:06:30.736>
    labels = ['interpreter-core', '3.9', '3.10', '3.11']
    title = 'IndendationError from multi-line indented statements'
    updated_at = <Date 2022-01-25.22:38:52.005>
    user = 'https://github.com/ucodery'

    bugs.python.org fields:

    activity = <Date 2022-01-25.22:38:52.005>
    actor = 'pablogsal'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-01-25.22:38:52.006>
    closer = 'pablogsal'
    components = ['Parser']
    creation = <Date 2021-12-15.23:06:30.736>
    creator = 'ucodery'
    dependencies = []
    files = ['50496']
    hgrepos = []
    issue_num = 46091
    keywords = ['patch']
    message_count = 7.0
    messages = ['408651', '408654', '408656', '408661', '408663', '411678', '411680']
    nosy_count = 4.0
    nosy_names = ['gvanrossum', 'lys.nikolaou', 'pablogsal', 'ucodery']
    pr_nums = ['30130', '30898', '30899']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue46091'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @ucodery
    Copy link
    Mannequin Author

    ucodery mannequin commented Dec 15, 2021

    At some point in 3.9 Python appears to have stopped accepting source that starts with an indent, then a '\', then the indented statement. From the lexical analysis 1 "Indentation cannot be split over multiple physical lines using backslashes; the whitespace up to the first backslash determines the indentation."

    Running the attached program under 3.8.12 I get:

    0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
    

    But running under 3.10.0 I get:

      File "/Users/jeremyp/tmp/nodent.py", line 3
        """Print a Fibonacci series up to n."""
        ^
    IndentationError: expected an indented block after function definition on line 1
    

    Running under 3.9.9 also gives an IndentationError, both with and without -X oldparser. So this doesn't seem directly related to the new parser, but seems likely it is fall out from the general grammar restructuring.

    IMHO it isn't a particularly nice feature for the language to have. Especially since not all lines like ' \' behave the same. But it was there and documented for many years, so should probably be put back. Does a core developer agree? That the implementation is not following the spec?

    @ucodery ucodery mannequin added 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Dec 15, 2021
    @pablogsal
    Copy link
    Member

    This is a side effect on the fix in:

    https://bugs.python.org/issue40847

    @pablogsal
    Copy link
    Member

    Unfortunately I am not sure if this is going to be easier to retrofit for the reasons exposed in the issue. I will try to take a look, but if you have some cycles to spare, a PR would be welcomed.

    @pablogsal
    Copy link
    Member

    nevermind, I am convinced is a bug. I filed a PR for it

    @ucodery
    Copy link
    Mannequin Author

    ucodery mannequin commented Dec 16, 2021

    Wow, this was a fast turnaround! I was going to spin some cycles on this, but would have not seen the solution in 50m.

    @pablogsal
    Copy link
    Member

    New changeset a0efc0c by Pablo Galindo Salgado in branch 'main':
    bpo-46091: Correctly calculate indentation levels for whitespace lines with continuation characters (GH-30130)
    a0efc0c

    @pablogsal
    Copy link
    Member

    New changeset 3fc8b74 by Pablo Galindo Salgado in branch '3.10':
    [3.10] bpo-46091: Correctly calculate indentation levels for whitespace lines with continuation characters (GH-30130). (GH-30898)
    3fc8b74

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant