Title: Fix a variable shadowing warning in Python-ast.c
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.7, Python 3.6, Python 3.3, Python 3.4, Python 3.5, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: OswinC, benjamin.peterson, brett.cannon, lukasz.langa, ncoghlan, yselivanov
Priority: low Keywords:

Created on 2017-07-03 19:21 by OswinC, last changed 2017-08-04 18:00 by lukasz.langa. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 2180 merged OswinC, 2017-07-03 19:21
PR 2181 merged OswinC, 2017-07-03 19:22
PR 2182 merged OswinC, 2017-07-03 19:22
PR 3001 merged lukasz.langa, 2017-08-04 17:59
Messages (5)
msg297609 - (view) Author: Yuan Chao Chou (OswinC) * Date: 2017-07-03 19:21
When Parser/ 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.
msg299208 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2017-07-26 04:53
What actually omits warnings about this?
msg299210 - (view) Author: Yuan Chao Chou (OswinC) * Date: 2017-07-26 06:26
This can be repro by setting -Wshadow-compatible-local when using gcc to compile Python-ast.c.
An example on my machine:
➜  cpython git:(69c0db5050) ✗ 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;
msg299754 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2017-08-04 17:52
The actual change is just three lines in Python-ast.c is generated.
msg299755 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2017-08-04 18:00
Date User Action Args
2017-08-04 18:00:35lukasz.langasetstatus: open -> closed
resolution: fixed
messages: + msg299755

stage: resolved
2017-08-04 17:59:28lukasz.langasetpull_requests: + pull_request3037
2017-08-04 17:52:51lukasz.langasetnosy: + lukasz.langa
messages: + msg299754
2017-08-02 01:51:16OswinCsettitle: A shadowing variable naming emitted for Python-ast.c -> Fix a variable shadowing warning in Python-ast.c
2017-07-26 06:26:47OswinCsetmessages: + msg299210
2017-07-26 04:53:41benjamin.petersonsetmessages: + msg299208
2017-07-08 18:38:06brett.cannonsetpriority: normal -> low
2017-07-08 18:37:59brett.cannonsettype: compile error -> enhancement
2017-07-08 03:00:08terry.reedysetnosy: + brett.cannon, ncoghlan, benjamin.peterson, yselivanov
2017-07-03 19:22:56OswinCsetpull_requests: + pull_request2619
2017-07-03 19:22:42OswinCsetpull_requests: + pull_request2618
2017-07-03 19:21:37OswinCsetpull_requests: + pull_request2617
2017-07-03 19:21:00OswinCcreate