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

Faulty suppression of 'as' keyword warning #48186

Closed
terryjreedy opened this issue Sep 22, 2008 · 8 comments
Closed

Faulty suppression of 'as' keyword warning #48186

terryjreedy opened this issue Sep 22, 2008 · 8 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@terryjreedy
Copy link
Member

BPO 3936
Nosy @terryjreedy, @amauryfa, @benjaminp
Files
  • fix_warning_after_import.patch
  • after_review.patch
  • 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 = 'https://github.com/benjaminp'
    closed_at = <Date 2008-09-25.20:46:41.322>
    created_at = <Date 2008-09-22.21:52:21.109>
    labels = ['interpreter-core']
    title = "Faulty suppression of 'as' keyword warning"
    updated_at = <Date 2008-09-25.20:46:41.321>
    user = 'https://github.com/terryjreedy'

    bugs.python.org fields:

    activity = <Date 2008-09-25.20:46:41.321>
    actor = 'benjamin.peterson'
    assignee = 'benjamin.peterson'
    closed = True
    closed_date = <Date 2008-09-25.20:46:41.322>
    closer = 'benjamin.peterson'
    components = ['Interpreter Core']
    creation = <Date 2008-09-22.21:52:21.109>
    creator = 'terry.reedy'
    dependencies = []
    files = ['11577', '11598']
    hgrepos = []
    issue_num = 3936
    keywords = ['patch']
    message_count = 8.0
    messages = ['73600', '73655', '73671', '73679', '73767', '73772', '73778', '73813']
    nosy_count = 4.0
    nosy_names = ['terry.reedy', 'amaury.forgeotdarc', 'koen', 'benjamin.peterson']
    pr_nums = []
    priority = 'high'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue3936'
    versions = ['Python 2.5']

    @terryjreedy
    Copy link
    Member Author

    Copied from c.l.p post by F. Lundh
    I have no idea if this has implications for warnings in 2.6
    ------------------------

    >  >>> from sympy.mpmath import specfun
    >  >>>
    >
    > So what could be suppressing the warning?
    [about 'as' becoming a keyword, when assigned to]

    a bug in Python 2.5, it seems:

    more f1.py
    as = 1
    as = 2
    as = 3
    python f1.py
    f1.py:1: Warning: 'as' will become a reserved keyword in Python 2.6
    f1.py:2: Warning: 'as' will become a reserved keyword in Python 2.6
    f1.py:3: Warning: 'as' will become a reserved keyword in Python 2.6

    more f2.py
    as = 1
    import os
    as = 3
    python f2.py
    f2.py:1: Warning: 'as' will become a reserved keyword in Python 2.6

    A quick look in parsetok.c reveals that it sets a "handling_import" flag
    when it stumbles upon an "import" statement, a flag that's later used to
    suppress the warning message. The bug is that the flag isn't reset
    until the parser sees an ENDMARKER token (end of file), instead of when
    it sees the next NEWLINE token.

    (if someone wants to submit this to bugs.python.org, be my guest)

    @terryjreedy terryjreedy added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Sep 22, 2008
    @koen
    Copy link
    Mannequin

    koen mannequin commented Sep 23, 2008

    I was wondering why I didn't have any warnings in my code in 2.5, when
    it started failing with errors on import in 2.6. Now I know.

    @benjaminp
    Copy link
    Contributor

    Attaching patch and test.

    @amauryfa
    Copy link
    Member

    I would be more comfortable if "started = 1" was also executed in the
    NEWLINE case. I'm not sure to understand the exact use of its value.

    And do you think if it's possible to add the type==SEMICOLON case?
    This would properly show the warning for:
    import sys; as = 3 # on the same line

    There are still some far-fetched constructs that do not warn, like:
    import sys as as
    but they are probably not worth the trouble.

    @benjaminp
    Copy link
    Contributor

    You're right; I should put it within the started block. Actually, no
    import cases are currently handled by the warning to avoid conflicting
    with "import foo as bar". This isn't really an issue, though because
    using the module name "as.attribute" will give a warning.

    If we were going to do this again, I would implement the warning in AST
    generation, but it's far too late for that.

    @amauryfa
    Copy link
    Member

    Patch is good to me.

    Actually 2.5 is not in "Release Candidate" stage, do we really need
    formal review?

    @benjaminp
    Copy link
    Contributor

    On Thu, Sep 25, 2008 at 2:46 AM, Amaury Forgeot d'Arc
    <report@bugs.python.org> wrote:

    Amaury Forgeot d'Arc <amauryfa@gmail.com> added the comment:

    Patch is good to me.

    Actually 2.5 is not in "Release Candidate" stage, do we really need
    formal review?

    Well, it certainly can't hurt. :)

    ----------
    keywords: -needs review


    Python tracker <report@bugs.python.org>
    <http://bugs.python.org/issue3936\>


    @benjaminp benjaminp self-assigned this Sep 25, 2008
    @benjaminp
    Copy link
    Contributor

    Fixed in r66618.

    @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
    interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants