Skip to content

Commit 24fd74d

Browse files
authored
Remove unnecessary global declarations and add noqa comments (#5865)
- Remove redundant global declarations where not needed - Add noqa: F824 comments to suppress linter warnings forglobal/nonlocal variables in autograph test where it is done on purpose Signed-off-by: Janusz Lisiecki <[email protected]>
1 parent 96212db commit 24fd74d

File tree

10 files changed

+10
-25
lines changed

10 files changed

+10
-25
lines changed

dali/python/nvidia/dali/_autograph/utils/ag_logging.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ def trace(*args):
108108

109109

110110
def get_verbosity():
111-
global verbosity_level
112111
if verbosity_level is not None:
113112
return verbosity_level
114113
return int(os.getenv(VERBOSITY_VAR_NAME, DEFAULT_VERBOSITY))

dali/python/nvidia/dali/_utils/dali_trace.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def set_tracing(*, enabled: bool = None, options={}):
4848

4949

5050
def is_tracing_enabled():
51-
global _origin_trace_enabled
5251
return _origin_trace_enabled
5352

5453

dali/test/python/autograph/pyct/static_analysis/test_activity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ def test_fn(a, b, c): # pylint:disable=unused-argument
705705
def test_global_symbol(self):
706706
def test_fn(c):
707707
global global_a
708-
global global_b
708+
global global_b # noqa: F824
709709
global_a = global_b + c
710710

711711
node, _ = self._parse_and_analyze(test_fn)
@@ -722,7 +722,7 @@ def test_nonlocal_symbol(self):
722722

723723
def test_fn(c):
724724
nonlocal nonlocal_a
725-
nonlocal nonlocal_b
725+
nonlocal nonlocal_b # noqa: F824
726726
nonlocal_a = nonlocal_b + c
727727

728728
node, _ = self._parse_and_analyze(test_fn)

dali/test/python/autograph/pyct/static_analysis/test_liveness.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ def test_fn(y):
503503

504504
def test_global_symbol(self):
505505
def test_fn(c):
506-
global global_a
506+
global global_a # noqa: F824
507507
global global_b
508508
if global_a:
509509
global_b = c
@@ -521,7 +521,7 @@ def test_nonlocal_symbol(self):
521521
nonlocal_b = 13
522522

523523
def test_fn(c):
524-
nonlocal nonlocal_a
524+
nonlocal nonlocal_a # noqa: F824
525525
nonlocal nonlocal_b
526526
if nonlocal_a:
527527
nonlocal_b = c

dali/test/python/autograph/pyct/static_analysis/test_reaching_definitions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ def test_fn():
425425

426426
def test_global(self):
427427
def test_fn():
428-
global global_a
428+
global global_a # noqa: F824
429429
global global_b
430430
if global_a:
431431
global_b = []
@@ -448,7 +448,7 @@ def test_nonlocal(self):
448448
b = 13
449449

450450
def test_fn():
451-
nonlocal a
451+
nonlocal a # noqa: F824
452452
nonlocal b
453453
if a:
454454
b = []
@@ -475,7 +475,7 @@ def test_fn():
475475
b = 13
476476

477477
def local_fn():
478-
nonlocal a, b
478+
nonlocal a, b # noqa: F824
479479
if a:
480480
b = []
481481
return a, b
@@ -515,7 +515,7 @@ def test_nonlocal(self):
515515
b = 13
516516

517517
def test_fn():
518-
nonlocal a
518+
nonlocal a # noqa: F824
519519
nonlocal b
520520
if a:
521521
b = []
@@ -542,7 +542,7 @@ def test_fn():
542542
b = 13
543543

544544
def local_fn():
545-
nonlocal a, b
545+
nonlocal a, b # noqa: F824
546546
if a:
547547
b = []
548548
return a, b

dali/test/python/autograph/pyct/static_analysis/test_type_inference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def bar():
471471
def test_local_function_closure_mutable_var(self):
472472
def test_fn(x: int):
473473
def foo():
474-
nonlocal x
474+
nonlocal x # noqa: F824
475475
return x
476476

477477
foo()

dali/test/python/operator_1/test_operator_origin_trace.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def capture_python_traces(fun, full_stack=False):
4646
full_stack : bool, optional
4747
Whether to capture the whole stack, by default False
4848
"""
49-
global extracted_stacks
5049
global base_frame
5150
base_frame = len(traceback.extract_stack()) if not full_stack else 0
5251

@@ -85,14 +84,11 @@ def capture_dali_traces(pipe_def):
8584

8685
def origin_trace():
8786
"""Either return trace using test operator or capture it via Python API"""
88-
global op_mode
8987
if op_mode == "dali.fn":
9088
return fn.origin_trace_dump()
9189
if op_mode == "dali.ops":
9290
return ops.OriginTraceDump()() # Yup, super obvious __init__ + __call__
9391
# elif op_mode == "python":
94-
global extracted_stacks
95-
global base_frame
9692
# Skip last frame as it differs from calling the fn.origin_trace_dump above.
9793
extracted_stacks.append(traceback.extract_stack()[base_frame:-1])
9894
return None
@@ -105,7 +101,6 @@ def origin_trace_glob(op_mode):
105101

106102

107103
def compare_traces(dali_tbs, python_tbs, end_glob=origin_trace_glob):
108-
global op_mode
109104
assert len(dali_tbs) == len(python_tbs)
110105
regex = fnmatch.translate(end_glob(op_mode))
111106
for dali_tb, python_tb in zip(dali_tbs, python_tbs):

dali/test/python/test_pool_utils.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ def capture_processes(pool):
2121
"""Need to be called to register the processes created by the pool. It is later used
2222
by the teardown_function to check if no process stayed alive after the test finished.
2323
"""
24-
global pool_processes
25-
global pool_threads
26-
global pools
2724
if pool is not None:
2825
pools.append(weakref.ref(pool))
2926
pool_processes.extend(pool.pids())
@@ -47,9 +44,6 @@ def teardown_function():
4744
4845
Be sure to call `capture_processes` in the test.
4946
"""
50-
global pool_processes
51-
global pool_threads
52-
global pools
5347
assert len(pool_processes), "No processes where tracked - did the test call capture_processes?"
5448
pools_not_collected = [pool_ref() is not None for pool_ref in pools]
5549
current_process = psutil.Process()

dali/test/python/webdataset_base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ def file_reader_pipeline(
105105

106106

107107
def generate_temp_index_file(tar_file_path):
108-
global wds2idx_script
109108
temp_index_file = tempfile.NamedTemporaryFile()
110109
assert_equals(
111110
call([wds2idx_script, tar_file_path, temp_index_file.name], stdout=open(os.devnull, "wb")),

qa/setup_packages.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,6 @@ def get_links_indices(packages, cuda_version):
714714

715715

716716
def main():
717-
global args
718717
if args.list:
719718
print_configs(args.cuda)
720719
elif args.num:

0 commit comments

Comments
 (0)