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

Remove TODOs in unused-variable tests #6162

Merged
merged 2 commits into from
Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions tests/functional/u/unused/unused_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def hello(arg):
return True
raise Exception

# pylint: disable=redefined-outer-name, wrong-import-position,misplaced-future
# pylint: disable=wrong-import-position,misplaced-future
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was worth surfacing the redefined-outer-name in these tests so you can more easily see that some warning is raised for the fishiness.

from __future__ import print_function
PATH = OS = collections = deque = None

Expand Down Expand Up @@ -94,6 +94,7 @@ def test_global():
""" Test various assignments of global
variables through imports.
"""
# pylint: disable=redefined-outer-name
global PATH, OS, collections, deque # [global-variable-not-assigned, global-variable-not-assigned]
from os import path as PATH
import os as OS
Expand All @@ -111,17 +112,15 @@ def function2():
try:
1 / 0
except ZeroDivisionError as error:
# TODO fix bug for not identifying unused variables in nested exceptions see issue #4391
try:
1 / 0
except ZeroDivisionError as error:
except ZeroDivisionError as error: # [redefined-outer-name]
raise Exception("") from error

def func():
try:
1 / 0
except ZeroDivisionError as error:
# TODO fix bug for not identifying unused variables in nested exceptions see issue #4391
try:
1 / 0
except error:
Expand All @@ -131,7 +130,6 @@ def func2():
try:
1 / 0
except ZeroDivisionError as error:
# TODO fix bug for not identifying unused variables in nested exceptions see issue #4391
try:
1 / 0
except:
Expand All @@ -144,7 +142,7 @@ def func3():
print(f"{error}")
try:
1 / 2
except TypeError as error: # [unused-variable]
except TypeError as error: # [unused-variable, redefined-outer-name]
print("warning")

def func4():
Expand All @@ -153,8 +151,7 @@ def func4():
except ZeroDivisionError as error: # [unused-variable]
try:
1 / 0
except ZeroDivisionError as error:
# TODO fix bug for not identifying unused variables in nested exceptions see issue #4391
except ZeroDivisionError as error: # [redefined-outer-name]
print("error")


Expand Down
25 changes: 14 additions & 11 deletions tests/functional/u/unused/unused_variable.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ unused-import:55:4:55:38:unused_import_from:Unused namedtuple imported from coll
unused-import:59:4:59:40:unused_import_in_function:Unused hexdigits imported from string:UNDEFINED
unused-variable:64:4:64:10:hello:Unused variable 'my_var':UNDEFINED
unused-variable:76:4:76:8:function:Unused variable 'aaaa':UNDEFINED
global-variable-not-assigned:97:4:97:39:test_global:Using global for 'PATH' but no assignment is done:UNDEFINED
global-variable-not-assigned:97:4:97:39:test_global:Using global for 'deque' but no assignment is done:UNDEFINED
unused-import:103:4:103:28:test_global:Unused platform imported from sys:UNDEFINED
unused-import:104:4:104:38:test_global:Unused version imported from sys as VERSION:UNDEFINED
unused-import:105:4:105:15:test_global:Unused import this:UNDEFINED
unused-import:106:4:106:19:test_global:Unused re imported as RE:UNDEFINED
unused-variable:110:4:110:10:function2:Unused variable 'unused':UNDEFINED
unused-variable:147:8:148:28:func3:Unused variable 'error':UNDEFINED
unused-variable:153:4:158:26:func4:Unused variable 'error':UNDEFINED
unused-variable:165:4:166:12:main:Unused variable 'e':UNDEFINED
undefined-loop-variable:172:10:172:11:main:Using possibly undefined loop variable 'e':UNDEFINED
global-variable-not-assigned:98:4:98:39:test_global:Using global for 'PATH' but no assignment is done:UNDEFINED
global-variable-not-assigned:98:4:98:39:test_global:Using global for 'deque' but no assignment is done:UNDEFINED
unused-import:104:4:104:28:test_global:Unused platform imported from sys:UNDEFINED
unused-import:105:4:105:38:test_global:Unused version imported from sys as VERSION:UNDEFINED
unused-import:106:4:106:15:test_global:Unused import this:UNDEFINED
unused-import:107:4:107:19:test_global:Unused re imported as RE:UNDEFINED
unused-variable:111:4:111:10:function2:Unused variable 'unused':UNDEFINED
redefined-outer-name:117:8:118:42:function2:Redefining name 'error' from outer scope (line 114):UNDEFINED
redefined-outer-name:145:8:146:28:func3:Redefining name 'error' from outer scope (line 141):UNDEFINED
unused-variable:145:8:146:28:func3:Unused variable 'error':UNDEFINED
unused-variable:151:4:155:26:func4:Unused variable 'error':UNDEFINED
redefined-outer-name:154:8:155:26:func4:Redefining name 'error' from outer scope (line 151):UNDEFINED
unused-variable:162:4:163:12:main:Unused variable 'e':UNDEFINED
undefined-loop-variable:169:10:169:11:main:Using possibly undefined loop variable 'e':UNDEFINED