Skip to contentSkip to conversation

python: fix flake8 F824 error

PATCH In review Rahul Sandhu 3 participants 3 messages Jul 31, 2025 – Oct 6, 2025 SELinux security module

lore
Share & tools
lore
#0 lore raw

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
index df34e0e6..8fa0c379 100644
@@ -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
index 10963e81..b41efd59 100644
@@ -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
index c8a3eb54..01a322ca 100644
@@ -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
index 2d526c94..3b87a869 100644
@@ -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
Acked-by on v1 1/1
#1 lore raw
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.html

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
index df34e0e6..8fa0c379 100644
@@ -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
index 10963e81..b41efd59 100644
@@ -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
index c8a3eb54..01a322ca 100644
@@ -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 -4
index 2d526c94..3b87a869 100644
@@ -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

maintainer
#2 lore raw
Quoted 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.html

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
index df34e0e6..8fa0c379 100644
@@ -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
index 10963e81..b41efd59 100644
@@ -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
index c8a3eb54..01a322ca 100644
@@ -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 -4
index 2d526c94..3b87a869 100644
@@ -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