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

Fix a variable shadowing warning in Python-ast.c #75024

Closed
OswinC mannequin opened this issue Jul 3, 2017 · 5 comments
Closed

Fix a variable shadowing warning in Python-ast.c #75024

OswinC mannequin opened this issue Jul 3, 2017 · 5 comments
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@OswinC
Copy link
Mannequin

OswinC mannequin commented Jul 3, 2017

BPO 30841
Nosy @brettcannon, @ncoghlan, @benjaminp, @ambv, @1st1, @OswinC
PRs
  • bpo-30841: Fix a shadow-compatible-local warning #2180
  • bpo-30841: Fix a shadow-compatible-local warning #2181
  • bpo-30841: Fix a shadow-compatible-local warning #2182
  • bpo-30841: Add author of the fix for #30841 to ACKS. #3001
  • 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-04.18:00:35.117>
    created_at = <Date 2017-07-03.19:21:00.693>
    labels = ['interpreter-core', 'type-feature', '3.7']
    title = 'Fix a variable shadowing warning in Python-ast.c'
    updated_at = <Date 2017-08-04.18:00:35.116>
    user = 'https://github.com/OswinC'

    bugs.python.org fields:

    activity = <Date 2017-08-04.18:00:35.116>
    actor = 'lukasz.langa'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-08-04.18:00:35.117>
    closer = 'lukasz.langa'
    components = ['Interpreter Core']
    creation = <Date 2017-07-03.19:21:00.693>
    creator = 'OswinC'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30841
    keywords = []
    message_count = 5.0
    messages = ['297609', '299208', '299210', '299754', '299755']
    nosy_count = 6.0
    nosy_names = ['brett.cannon', 'ncoghlan', 'benjamin.peterson', 'lukasz.langa', 'yselivanov', 'OswinC']
    pr_nums = ['2180', '2181', '2182', '3001']
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue30841'
    versions = ['Python 2.7', 'Python 3.3', 'Python 3.4', 'Python 3.5', 'Python 3.6', 'Python 3.7']

    @OswinC
    Copy link
    Mannequin Author

    OswinC mannequin commented Jul 3, 2017

    When Parser/asdl_c.py is composing the content of Python/Python-ast.c, it uses "value" to name the variables in inner blocks, which can shadow the variables named the same in outer blocks. It would be a good practice to avoid the shadowing naming to prevent the variables from being misused.

    @OswinC OswinC mannequin added build The build process and cross-build 3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Jul 3, 2017
    @brettcannon brettcannon added type-feature A feature request or enhancement and removed build The build process and cross-build labels Jul 8, 2017
    @benjaminp
    Copy link
    Contributor

    What actually omits warnings about this?

    @OswinC
    Copy link
    Mannequin Author

    OswinC mannequin commented Jul 26, 2017

    This can be repro by setting -Wshadow-compatible-local when using gcc to compile Python-ast.c.
    An example on my machine:
    ➜ cpython git:(69c0db5) ✗ gcc-7 -Wshadow-compatible-local -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I./Include -I. -I/usr/local/opt/readline/include -I/usr/local/opt/openssl/include -I/Users/python/.pyenv/versions/3.6.1/include -I/usr/local/include -I/Users/python/.pyenv/versions/3.6.1/include/python3.6m -c Python/Python-ast.c -o build/temp.macosx-10.12-x86_64-3.6/Python-ast.o
    Python/Python-ast.c: In function 'obj2ast_stmt':
    Python/Python-ast.c:4586:25: warning: declaration of 'value' shadows a previous local [-Wshadow=compatible-local]
    expr_ty value;
    ^~~~~
    Python/Python-ast.c:4570:17: note: shadowed declaration is here
    expr_ty value;
    ^~~~~

    @OswinC OswinC mannequin changed the title A shadowing variable naming emitted for Python-ast.c Fix a variable shadowing warning in Python-ast.c Aug 2, 2017
    @ambv
    Copy link
    Contributor

    ambv commented Aug 4, 2017

    The actual change is just three lines in asdl_c.py. Python-ast.c is generated.

    @ambv
    Copy link
    Contributor

    ambv commented Aug 4, 2017

    Thanks!

    @ambv ambv closed this as completed Aug 4, 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 interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants