Skip to content

TypeError instead of SyntaxError for syntactically invalid gen exp #46491

Closed

Description

@ntc2
mannequin
BPO 2238
Nosy @amauryfa, @ntc2

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 2008-03-20.17:40:02.944>
created_at = <Date 2008-03-05.00:53:15.666>
labels = []
title = 'TypeError instead of SyntaxError for syntactically invalid gen exp'
updated_at = <Date 2008-03-20.17:40:02.943>
user = 'https://github.com/ntc2'

bugs.python.org fields:

activity = <Date 2008-03-20.17:40:02.943>
actor = 'jafo'
assignee = 'none'
closed = True
closed_date = <Date 2008-03-20.17:40:02.944>
closer = 'jafo'
components = ['None']
creation = <Date 2008-03-05.00:53:15.666>
creator = 'ntc2'
dependencies = []
files = []
hgrepos = []
issue_num = 2238
keywords = []
message_count = 3.0
messages = ['63273', '63274', '64184']
nosy_count = 3.0
nosy_names = ['jafo', 'amaury.forgeotdarc', 'ntc2']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue2238'
versions = ['Python 2.5']

Activity

  1. ntc2 commented on Mar 5, 2008

    ntc2mannequin
    MannequinAuthor

    I have a file f1.py

    $ cat f1.py
    import os
    (lambda **x:x)(**dict(y,y for y in ()))

    and when I run it

    $ python f1.py
    Traceback (most recent call last):
      File "f1.py", line 1, in <module>
        import os
    TypeError: 'int' object is not iterable

    Notice that the TypeError exception is from the import os on line 1.
    But the import isn't the problem. The problem is the illegal
    generator expression on line 2. I.e. if

    $ cat f2.py
    #import os
    dict(y,y for y in ())

    then

    $ python f2.py
      File "f2.py", line 2
        dict(y,y for y in ())
    SyntaxError: Generator expression must be parenthesized if not sole argument

    The mess

    (lambda **x:x)(**dict(y,y for y in ()))

    is a simplified version of something I had about 100 lines into a
    file, but the resulting TypeError still complains about an import on
    line 1, which is really confusing.

    I'm using

    Python 2.5.2 (r252:60911, Mar 4 2008, 14:33:51)
    [GCC 3.4.4] on linux2

    for python.

    ################################################################################

    The above is probably a good enough description, but here's some more
    weirdness in case it's helpful:

    Some variations of f1.py cause the same error, but others don't.
    E.g. if f4.py is

    for c in [1]: pass
    (lambda **x:x)(**dict(y,y for y in ()))

    I get

    Traceback (most recent call last):
      File "f4.py", line 1, in <module>
        for c in [1]: pass
    TypeError: 'int' object is not iterable

    as before. But if f5.py is

    for c in "1": pass
    (lambda **x:x)(**dict(y,y for y in ()))

    running the script results in no output and a successful run

    $ echo $?
    0

    Finally, if f6.py is just the single line

    (lambda **x:x)(**dict(y,y for y in ()))

    then my 2.5.2 python has the same successful with no output result as
    for f5.py, but if I run f6.py in an older

    Python 2.5 (r25:51908, Oct 30 2006, 16:20:39)
    [GCC 3.4.4] on linux2

    python I get

    Exception exceptions.SyntaxError: ('Generator expression must be
    parenthesized if not sole argument', 1) in 'garbage collection' ignored
    Fatal Python error: unexpected exception during garbage collection
    zsh: abort (core dumped) python f6.py

    The older 2.5 python runs f5.py successfully with no output like 2.5.2 does.

    I searched the bug tracker for "TypeError: 'int' object is not
    iterable" and didn't find anything, so I'm assuming this bug is
    unknown. I'm sure someone will let me know if I'm mistaken =)

    I'd guess the problem has to do with a bad parse.

  2. amauryfa commented on Mar 5, 2008

    @amauryfa
    Contributor

    Interestingly, in debug mode, the message "XXX undetected error" is
    printed to stderr.
    And this gives the solution: in ast.c, some calls did not check the
    return status.

    Committed revision 61240, will backport to 2.5.
    Thanks for the report!
    Thanks for the report!

  3. jafo commented on Mar 20, 2008

    jafomannequin
    Mannequin

    Back-ported to 2.5 and committed in rev 61675.

  4. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions