Navigation Menu

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

Only check for print and exec parentheses cases for SyntaxError, not subclasses #75344

Closed
mjpieters mannequin opened this issue Aug 9, 2017 · 11 comments
Closed

Only check for print and exec parentheses cases for SyntaxError, not subclasses #75344

mjpieters mannequin opened this issue Aug 9, 2017 · 11 comments
Labels
3.7 (EOL) end of life easy interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@mjpieters
Copy link
Mannequin

mjpieters mannequin commented Aug 9, 2017

BPO 31161
Nosy @mjpieters, @stevendaprano, @ambv, @serhiy-storchaka
PRs
  • bpo-31161: only check for parens error for SyntaxError #3082
  • bpo-31161: only check for parens error for SyntaxError #3083
  • 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 2017-08-22.20:17:57.125>
    created_at = <Date 2017-08-09.13:31:18.767>
    labels = ['interpreter-core', 'easy', 'type-bug', '3.7']
    title = 'Only check for print and exec parentheses cases for SyntaxError, not subclasses'
    updated_at = <Date 2017-08-22.20:17:57.124>
    user = 'https://github.com/mjpieters'

    bugs.python.org fields:

    activity = <Date 2017-08-22.20:17:57.124>
    actor = 'lukasz.langa'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-08-22.20:17:57.125>
    closer = 'lukasz.langa'
    components = ['Interpreter Core']
    creation = <Date 2017-08-09.13:31:18.767>
    creator = 'mjpieters'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31161
    keywords = ['easy (C)']
    message_count = 11.0
    messages = ['300002', '300003', '300076', '300109', '300158', '300208', '300214', '300220', '300221', '300718', '300719']
    nosy_count = 4.0
    nosy_names = ['mjpieters', 'steven.daprano', 'lukasz.langa', 'serhiy.storchaka']
    pr_nums = ['3082', '3083']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue31161'
    versions = ['Python 3.6', 'Python 3.7']

    @mjpieters
    Copy link
    Mannequin Author

    mjpieters mannequin commented Aug 9, 2017

    SyntaxError.init() checks for the print and exec error cases where the user forgot to use parentheses:

    >>> exec 1
      File "<stdin>", line 1
        exec 1
             ^
    SyntaxError: Missing parentheses in call to 'exec'
    
    >>> print 1
      File "<stdin>", line 1
        print 1
              ^
    SyntaxError: Missing parentheses in call to 'print'

    However, this check is also applied to *subclasses* of SyntaxError:

    >>> if True:
    ... print "Look ma, no parens!"
      File "<stdin>", line 2
        print "Look ma, no parens!"
            ^
    IndentationError: Missing parentheses in call to 'print'

    and

    >>> compile('if 1:\n    1\n\tprint "Look ma, tabs!"', '', 'single')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "", line 3
        print "Look ma, tabs!"
                             ^
    TabError: Missing parentheses in call to 'print'

    Perhaps the check needs to be limited to just the exact type.

    @mjpieters
    Copy link
    Mannequin Author

    mjpieters mannequin commented Aug 9, 2017

    @stevendaprano
    Copy link
    Member

    I'm not sure whether this is a bug or a feature.

    In the examples you show, we have *both* an IndentationError/TabError and missing parentheses around print. So I'm almost inclined to say that this is right:

    • you get an IndentationError (or TabError);

    • and the error message *also* tells you that print is missing parens.

    Two errors for the price of one!

    I'm not sure that I would have designed it this way from scratch, but given that it already exists I'm not sure that it should be "fixed".

    In any case, since the error message itself is not part of the public API, I don't think there's any problem in changing it in a bug-fix release. So *if* we change this, we can change it in 3.6.

    @stevendaprano stevendaprano added interpreter-core (Objects, Python, Grammar, and Parser dirs) 3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error labels Aug 10, 2017
    @mjpieters
    Copy link
    Mannequin Author

    mjpieters mannequin commented Aug 10, 2017

    It's confusing; a syntax error reports on the first error found, not two errors at once. The TabError or IndentationError exception detail message itself is lost (it should be "IndentationError: Improper mixture of spaces and tabs." or "TabError: Improper indentation.", respectively). So you end up with an end-user scratching their head, the two parts of the message make no sense together.

    @serhiy-storchaka
    Copy link
    Member

    Perhaps the check needs to be limited to just the exact type.

    Looks reasonable to me. Do you want to provide a PR Martijn?

    @stevendaprano
    Copy link
    Member

    > Perhaps the check needs to be limited to just the exact type.
    Looks reasonable to me. Do you want to provide a PR Martijn?

    You realise that is making the current traceback *less* informative
    instead of more informative? I think that's going backwards -- useful
    information about the syntax errors are being discarded. "Practicality
    beats purity" -- the current behaviour is helpful, even if it mixes
    information about two errors into one traceback.

    @serhiy-storchaka
    Copy link
    Member

    The current traceback is incorrect. It mixes exception type and message from different errors.

    @mjpieters
    Copy link
    Mannequin Author

    mjpieters mannequin commented Aug 13, 2017

    This does not increase clarity. It creates confusion.

    There are two distinct syntax errors, and they should be reported separately, just like print "abc" 42 is two syntax errors; you'll hear about the second one once the first one is fixed.

    @mjpieters
    Copy link
    Mannequin Author

    mjpieters mannequin commented Aug 13, 2017

    Disregard my last message, I misread Serhiy's sentence (read 'correct' for 'incorrect').

    @ambv
    Copy link
    Contributor

    ambv commented Aug 22, 2017

    New changeset 680f04a by Łukasz Langa (Martijn Pieters) in branch '3.6':
    bpo-31161: only check for parens error for SyntaxError (bpo-3083)
    680f04a

    @ambv
    Copy link
    Contributor

    ambv commented Aug 22, 2017

    New changeset 772d809 by Łukasz Langa (Martijn Pieters) in branch 'master':
    bpo-31161: only check for parens error for SyntaxError (bpo-3082)
    772d809

    @ambv ambv closed this as completed Aug 22, 2017
    @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.7 (EOL) end of life easy interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants