8000 compile() doesn't work on ImportFrom with level=None · Issue #57645 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

compile() doesn't work on ImportFrom with level=None #57645

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

Closed
JanoschGrf mannequin opened this issue Nov 20, 2011 · 8 comments
Closed

compile() doesn't work on ImportFrom with level=None #57645

JanoschGrf mannequin opened this issue Nov 20, 2011 · 8 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@JanoschGrf
Copy link
Mannequin
JanoschGrf mannequin commented Nov 20, 2011
BPO 13436
Nosy @terryjreedy, @amauryfa, @vstinner, @benjaminp, @berkerpeksag
Files
  • issue13436.patch
  • issue13436.py
  • 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 2016-04-29.16:50:20.729>
    created_at = <Date 2011-11-20.00:04:38.730>
    labels = ['interpreter-core', 'type-bug']
    title = "compile() doesn't work on ImportFrom with level=None"
    updated_at = <Date 2016-04-29.16:50:20.728>
    user = 'https://bugs.python.org/JanoschGrf'

    bugs.python.org fields:

    activity = <Date 2016-04-29.16:50:20.728>
    actor = 'berker.peksag'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-04-29.16:50:20.729>
    closer = 'berker.peksag'
    components = ['Interpreter Core']
    creation = <Date 2011-11-20.00:04:38.730>
    creator = 'Janosch.Gr\xc3\xa4f'
    dependencies = []
    files = ['23739', '42653']
    hgrepos = []
    issue_num = 13436
    keywords = ['patch']
    message_count = 8.0
    messages = ['147972', '148007', '148020', '148143', '148144', '148371', '264509', '264511']
    nosy_count = 7.0
    nosy_names = ['terry.reedy', 'amaury.forgeotdarc', 'vstinner', 'benjamin.peterson', 'python-dev', 'berker.peksag', 'Janosch.Gr\xc3\xa4f']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue13436'
    versions = ['Python 3.2', 'Python 3.3']

    @JanoschGrf
    Copy link
    Mannequin Author
    JanoschGrf mannequin commented Nov 20, 2011

    The documentation for ast says that arguments that are marked with a '?' in the abstract grammar are optional and can therefore be None.
    When I try to compile a Module node which contains an ImportFrom node with attribute level=None compile() throws an exception:

    Module(body=[ImportFrom(module='time', names=[alias(name='sleep', asname=None), alias(name='time', asname=None)], level=None, lineno=0, col_offset=0)])

    Traceback (most recent call last):
      File "g0.py", line 423, in <module>
        p.main()
      File "g0.py", line 65, in main
        self.reproduce("g1.pyc")
      File "g0.py", line 85, in reproduce
        co = self.generate_bytecode(st, genome)
      File "g0.py", line 243, in generate_bytecode
        co = compile(st, id, "exec")
    ValueError: invalid integer value: ��������

    So, I tried to set level=0:
    Module(body=[ImportFrom(module='time', names=[alias(name='sleep', asname=None), alias(name='time', asname=None)], level=0, lineno=0, col_offset=0)])

    and everything worked fine.

    BTW: The unprintable bytes in the error message are:
    ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd

    @JanoschGrf JanoschGrf mannequin assigned docspython Nov 20, 2011
    @JanoschGrf JanoschGrf mannequin added docs Documentation in the Doc dir interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Nov 20, 2011
    @amauryfa
    Copy link
    Contributor

    Here is a patch for the bad error message (PyBytes_AS_BYTES after PyObject_Repr, bah)

    @benjaminp
    Copy link
    Contributor

    LGTM.

    @python-dev
    Copy link
    Mannequin
    python-dev mannequin commented Nov 22, 2011

    New changeset ffcdfc534942 by Amaury Forgeot d'Arc in branch '3.2':
    Issue bpo-13436: Fix a bogus error message when an AST object was passed
    http://hg.python.org/cpython/rev/ffcdfc534942

    New changeset 470f7d7c57ce by Amaury Forgeot d'Arc in branch '3.2':
    Issue bpo-13436: commit regenerated Python-ast.c
    http://hg.python.org/cpython/rev/470f7d7c57ce

    @amauryfa
    Copy link
    Contributor

    I fixed the bogus error message, but "level=None" is still not allowed, whereas the docs promise that optional values can be None.

    @terryjreedy
    Copy link
    Member

    Does this apply to 2.7 as well?

    I believe msg148146 is due to a commit message typo.

    @birkenfeld birkenfeld removed the docs Documentation in the Doc dir label Oct 8, 2013
    @berkerpeksag
    Copy link
    Member
    level=None is now allowed: https://hg.python.org/cpython/file/default/Python/Python-ast.c#l5224 (see line 5224 to 5232) I converted the example in msg147972 to a Python script. test_bad_integer is still useful as it uses the required 'lineno' field. I will also commit issue13436.py as a test case.

    @python-dev
    Copy link
    Mannequin
    python-dev mannequin commented Apr 29, 2016

    New changeset 59638baee25e by Berker Peksag in branch 'default':
    Issue bpo-13436: Add a test to make sure that ast.ImportFrom(level=None) works
    https://hg.python.org/cpython/rev/59638baee25e

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    hauntsaninja added a commit to hauntsaninja/cpython that referenced this issue May 19, 2022
    This doesn't happen naturally, but is allowed by the ASDL and compiler.
    We don't want to change ASDL for backward compatibility reasons
    (python#57645, python#92987)
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 5, 2022
    …GH-92992)
    
    This doesn't happen naturally, but is allowed by the ASDL and compiler.
    We don't want to change ASDL for backward compatibility reasons
    (pythonGH-57645, pythonGH-92987)
    (cherry picked from commit 200c9a8)
    
    Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
    isidentical pushed a commit that referenced this issue Sep 5, 2022
    This doesn't happen naturally, but is allowed by the ASDL and compiler.
    We don't want to change ASDL for backward compatibility reasons
    (#57645, #92987)
    isidentical pushed a commit to isidentical/cpython that referenced this issue Sep 5, 2022
    …ythonGH-92992)
    
    This doesn't happen naturally, but is allowed by the ASDL and compiler.
    We don't want to change ASDL for backward compatibility reasons
    (pythonGH-57645, pythonGH-92987)
    (cherry picked from commit 200c9a8)
    
    Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
    miss-islington added a commit that referenced this issue Sep 5, 2022
    This doesn't happen naturally, but is allowed by the ASDL and compiler.
    We don't want to change ASDL for backward compatibility reasons
    (GH-57645, GH-92987)
    (cherry picked from commit 200c9a8)
    
    Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
    isidentical added a commit that referenced this issue Sep 6, 2022
    ) (GH-96593)
    
    This doesn't happen naturally, but is allowed by the ASDL and compiler.
    We don't want to change ASDL for backward compatibility reasons
    (GH-57645, GH-92987)
    (cherry picked from commit 200c9a8)
    
    Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
    
    Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Development

    No branches or pull requests

    5 participants
    0