python: fix flake8 F824 error
PATCH 1/1 python: fix flake8 F824 error
This fixes failing CI[1]. From the flake8 documentation[2]:
Quoted 1 line
global name / nonlocal name is unused: name is never assigned in scope
Meaning that a global only needs to be defined with the global keyword in scope when it's being assigned to; not when it's being read.
[1] https://github.com/SELinuxProject/selinux/actions/runs/16623315767/job/47032933729
[2] https://flake8.pycqa.org/en/latest/user/error-codes.html
--- mcstrans/share/util/mlstrans-test | 4 ++-- python/semanage/seobject.py | 1 - python/sepolgen/src/sepolgen/refparser.py | 2 +- python/sepolicy/sepolicy/__init__.py | 3 --- 4 files changed, 3 insertions(+), 7 deletions(-)
mcstrans/share/util/mlstrans-test +2 -2
@@ -8,7 +8,7 @@ errors = 0 def untrans(trans, val): - global errors, verbose + global errors (rc, raw) = selinux.selinux_trans_to_raw_context(trans) if raw != val: print("untrans: '%s' -> '%s' != '%s' FAILED" % (trans, raw, val))
@@ -19,7 +19,7 @@ def untrans(trans, val): def trans(raw, val): - global errors, verbose + global errors (rc, trans) = selinux.selinux_raw_to_trans_context(raw) if trans != val: print("trans: '%s' -> '%s' != '%s' FAILED" % (raw, trans, val))
python/semanage/seobject.py +0 -1
@@ -244,7 +244,6 @@ class semanageRecords: args = None def __init__(self, args = None): - global handle if args: # legacy code - args was store originally if isinstance(args, str):
python/sepolgen/src/sepolgen/refparser.py +1 -1
@@ -1038,7 +1038,7 @@ def p_quoted_filename(p): # def p_error(tok): - global error, parse_file, success, parser + global error, success error = "%s: Syntax error on line %d %s [type=%s]" % (parse_file, tok.lineno, tok.value, tok.type) print(error) success = False
python/sepolicy/sepolicy/__init__.py +0 -3
@@ -195,7 +195,6 @@ def init_policy(): policy(policy_file) def info(setype, name=None): - global _pol if not _pol: init_policy()
@@ -354,7 +353,6 @@ def _setools_rule_to_dict(rule): def search(types, seinfo=None): - global _pol if not _pol: init_policy() if not seinfo:
@@ -936,7 +934,6 @@ def get_all_roles(): if roles: return roles - global _pol if not _pol: init_policy()
Signature · 1 line
2.50.1
Quoted 5 lines · Rahul Sandhu
This fixes failing CI[1]. From the flake8 documentation[2]:
Quoted 1 line
global name / nonlocal name is unused: name is never assigned in scope
Quoted 7 lines
Meaning that a global only needs to be defined with the global keyword in scope when it's being assigned to; not when it's being read.
[1] https://github.com/SELinuxProject/selinux/actions/runs/16623315767/job/47032933729
[2] https://flake8.pycqa.org/en/latest/user/error-codes.htmlSigned-off-by Rahul Sandhu <[email protected]>
Quoted 86 lines
--- mcstrans/share/util/mlstrans-test | 4 ++-- python/semanage/seobject.py | 1 - python/sepolgen/src/sepolgen/refparser.py | 2 +- python/sepolicy/sepolicy/__init__.py | 3 --- 4 files changed, 3 insertions(+), 7 deletions(-)mcstrans/share/util/mlstrans-test +2
-2@@ -8,7 +8,7 @@ errors = 0 def untrans(trans, val): - global errors, verbose + global errors (rc, raw) = selinux.selinux_trans_to_raw_context(trans) if raw != val: print("untrans: '%s' -> '%s' != '%s' FAILED" % (trans, raw, val))@@ -19,7 +19,7 @@ def untrans(trans, val): def trans(raw, val): - global errors, verbose + global errors (rc, trans) = selinux.selinux_raw_to_trans_context(raw) if trans != val: print("trans: '%s' -> '%s' != '%s' FAILED" % (raw, trans, val))python/semanage/seobject.py +0
-1@@ -244,7 +244,6 @@ class semanageRecords: args = None def __init__(self, args = None): - global handle if args: # legacy code - args was store originally if isinstance(args, str):python/sepolgen/src/sepolgen/refparser.py +1
-1@@ -1038,7 +1038,7 @@ def p_quoted_filename(p): # def p_error(tok): - global error, parse_file, success, parser + global error, success error = "%s: Syntax error on line %d %s [type=%s]" % (parse_file, tok.lineno, tok.value, tok.type) print(error) success = Falsepython/sepolicy/sepolicy/__init__.py +0
-4@@ -195,7 +195,6 @@ def init_policy(): policy(policy_file) def info(setype, name=None): - global _pol if not _pol: init_policy()@@ -354,7 +353,6 @@ def _setools_rule_to_dict(rule): def search(types, seinfo=None): - global _pol if not _pol: init_policy() if not seinfo:@@ -936,7 +934,6 @@ def get_all_roles(): if roles: return roles - global _pol if not _pol: init_policy() --2.50.1
Stephen Smalley
maintainerQuoted 10 lines · James Carter
Quoted 8 lines · Rahul Sandhu
This fixes failing CI[1]. From the flake8 documentation[2]:
Quoted 1 line
global name / nonlocal name is unused: name is never assigned in scope
Meaning that a global only needs to be defined with the global keyword in scope when it's being assigned to; not when it's being read.
Quoted 6 lines
Quoted 4 lines
[1] https://github.com/SELinuxProject/selinux/actions/runs/16623315767/job/47032933729
[2] https://flake8.pycqa.org/en/latest/user/error-codes.htmlSigned-off-by Rahul Sandhu <[email protected]>Acked-by James Carter <[email protected]>
Thanks, merged.
Quoted 88 lines
Quoted 87 lines
--- mcstrans/share/util/mlstrans-test | 4 ++-- python/semanage/seobject.py | 1 - python/sepolgen/src/sepolgen/refparser.py | 2 +- python/sepolicy/sepolicy/__init__.py | 3 --- 4 files changed, 3 insertions(+), 7 deletions(-)mcstrans/share/util/mlstrans-test +2
-2@@ -8,7 +8,7 @@ errors = 0 def untrans(trans, val): - global errors, verbose + global errors (rc, raw) = selinux.selinux_trans_to_raw_context(trans) if raw != val: print("untrans: '%s' -> '%s' != '%s' FAILED" % (trans, raw, val))@@ -19,7 +19,7 @@ def untrans(trans, val): def trans(raw, val): - global errors, verbose + global errors (rc, trans) = selinux.selinux_raw_to_trans_context(raw) if trans != val: print("trans: '%s' -> '%s' != '%s' FAILED" % (raw, trans, val))python/semanage/seobject.py +0
-1@@ -244,7 +244,6 @@ class semanageRecords: args = None def __init__(self, args = None): - global handle if args: # legacy code - args was store originally if isinstance(args, str):python/sepolgen/src/sepolgen/refparser.py +1
-1@@ -1038,7 +1038,7 @@ def p_quoted_filename(p): # def p_error(tok): - global error, parse_file, success, parser + global error, success error = "%s: Syntax error on line %d %s [type=%s]" % (parse_file, tok.lineno, tok.value, tok.type) print(error) success = Falsepython/sepolicy/sepolicy/__init__.py +0
-4@@ -195,7 +195,6 @@ def init_policy(): policy(policy_file) def info(setype, name=None): - global _pol if not _pol: init_policy()@@ -354,7 +353,6 @@ def _setools_rule_to_dict(rule): def search(types, seinfo=None): - global _pol if not _pol: init_policy() if not seinfo:@@ -936,7 +934,6 @@ def get_all_roles(): if roles: return roles - global _pol if not _pol: init_policy() --2.50.1