* [PATCH] python: fix flake8 F824 error
@ 2025-07-31 10:22 Rahul Sandhu
2025-08-12 15:18 ` James Carter
0 siblings, 1 reply; 4+ messages in thread
From: Rahul Sandhu @ 2025-07-31 10:22 UTC (permalink / raw)
To: selinux; +Cc: Rahul Sandhu
This fixes failing CI[1]. From the flake8 documentation[2]:
> 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
Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
---
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(-)
diff --git a/mcstrans/share/util/mlstrans-test b/mcstrans/share/util/mlstrans-test
index df34e0e6..8fa0c379 100644
--- a/mcstrans/share/util/mlstrans-test
+++ b/mcstrans/share/util/mlstrans-test
@@ -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))
diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py
index 10963e81..b41efd59 100644
--- a/python/semanage/seobject.py
+++ b/python/semanage/seobject.py
@@ -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):
diff --git a/python/sepolgen/src/sepolgen/refparser.py b/python/sepolgen/src/sepolgen/refparser.py
index c8a3eb54..01a322ca 100644
--- a/python/sepolgen/src/sepolgen/refparser.py
+++ b/python/sepolgen/src/sepolgen/refparser.py
@@ -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
diff --git a/python/sepolicy/sepolicy/__init__.py b/python/sepolicy/sepolicy/__init__.py
index 2d526c94..3b87a869 100644
--- a/python/sepolicy/sepolicy/__init__.py
+++ b/python/sepolicy/sepolicy/__init__.py
@@ -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
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] python: fix flake8 F824 error
2025-07-31 10:22 Rahul Sandhu
@ 2025-08-12 15:18 ` James Carter
2025-10-06 15:06 ` Stephen Smalley
0 siblings, 1 reply; 4+ messages in thread
From: James Carter @ 2025-08-12 15:18 UTC (permalink / raw)
To: Rahul Sandhu; +Cc: selinux
On Thu, Jul 31, 2025 at 6:34 AM Rahul Sandhu <nvraxn@gmail.com> wrote:
>
> This fixes failing CI[1]. From the flake8 documentation[2]:
>
> > 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
>
> Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
Acked-by: James Carter <jwcart2@gmail.com>
> ---
> 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(-)
>
> diff --git a/mcstrans/share/util/mlstrans-test b/mcstrans/share/util/mlstrans-test
> index df34e0e6..8fa0c379 100644
> --- a/mcstrans/share/util/mlstrans-test
> +++ b/mcstrans/share/util/mlstrans-test
> @@ -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))
> diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py
> index 10963e81..b41efd59 100644
> --- a/python/semanage/seobject.py
> +++ b/python/semanage/seobject.py
> @@ -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):
> diff --git a/python/sepolgen/src/sepolgen/refparser.py b/python/sepolgen/src/sepolgen/refparser.py
> index c8a3eb54..01a322ca 100644
> --- a/python/sepolgen/src/sepolgen/refparser.py
> +++ b/python/sepolgen/src/sepolgen/refparser.py
> @@ -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
> diff --git a/python/sepolicy/sepolicy/__init__.py b/python/sepolicy/sepolicy/__init__.py
> index 2d526c94..3b87a869 100644
> --- a/python/sepolicy/sepolicy/__init__.py
> +++ b/python/sepolicy/sepolicy/__init__.py
> @@ -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
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] python: fix flake8 F824 error
2025-08-12 15:18 ` James Carter
@ 2025-10-06 15:06 ` Stephen Smalley
0 siblings, 0 replies; 4+ messages in thread
From: Stephen Smalley @ 2025-10-06 15:06 UTC (permalink / raw)
To: James Carter; +Cc: Rahul Sandhu, selinux
On Tue, Aug 12, 2025 at 11:45 AM James Carter <jwcart2@gmail.com> wrote:
>
> On Thu, Jul 31, 2025 at 6:34 AM Rahul Sandhu <nvraxn@gmail.com> wrote:
> >
> > This fixes failing CI[1]. From the flake8 documentation[2]:
> >
> > > 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
> >
> > Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
>
> Acked-by: James Carter <jwcart2@gmail.com>
Thanks, merged.
>
> > ---
> > 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(-)
> >
> > diff --git a/mcstrans/share/util/mlstrans-test b/mcstrans/share/util/mlstrans-test
> > index df34e0e6..8fa0c379 100644
> > --- a/mcstrans/share/util/mlstrans-test
> > +++ b/mcstrans/share/util/mlstrans-test
> > @@ -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))
> > diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py
> > index 10963e81..b41efd59 100644
> > --- a/python/semanage/seobject.py
> > +++ b/python/semanage/seobject.py
> > @@ -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):
> > diff --git a/python/sepolgen/src/sepolgen/refparser.py b/python/sepolgen/src/sepolgen/refparser.py
> > index c8a3eb54..01a322ca 100644
> > --- a/python/sepolgen/src/sepolgen/refparser.py
> > +++ b/python/sepolgen/src/sepolgen/refparser.py
> > @@ -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
> > diff --git a/python/sepolicy/sepolicy/__init__.py b/python/sepolicy/sepolicy/__init__.py
> > index 2d526c94..3b87a869 100644
> > --- a/python/sepolicy/sepolicy/__init__.py
> > +++ b/python/sepolicy/sepolicy/__init__.py
> > @@ -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
> >
> >
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-10-06 15:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <CAP JOzTBrgKgzf2M4VRXXG_1=wSd-Zf-xGrp7J6w=o34 adGCg@mail.gmail.com>
2025-09-25 5:40 ` [PATCH] python: fix flake8 F824 error Rahul Sandhu
2025-07-31 10:22 Rahul Sandhu
2025-08-12 15:18 ` James Carter
2025-10-06 15:06 ` Stephen Smalley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).