From: Donald Hunter <donald.hunter@gmail.com>
To: "Donald Hunter" <donald.hunter@gmail.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Paolo Abeni" <pabeni@redhat.com>,
"Simon Horman" <horms@kernel.org>,
"Matthieu Baerts (NGI0)" <matttbe@kernel.org>,
"Gal Pressman" <gal@nvidia.com>,
"Jan Stancek" <jstancek@redhat.com>,
"Hangbin Liu" <liuhangbin@gmail.com>,
"Nimrod Oren" <noren@nvidia.com>,
netdev@vger.kernel.org, "Jonathan Corbet" <corbet@lwn.net>,
"Asbjørn Sloth Tønnesen" <ast@fiberby.net>,
"Mauro Carvalho Chehab" <mchehab+huawei@kernel.org>,
"Jacob Keller" <jacob.e.keller@intel.com>,
"Ruben Wauters" <rubenru09@aol.com>,
linux-doc@vger.kernel.org
Subject: [PATCH net-next v1 06/13] tools: ynl: fix pylint global variable related warnings
Date: Wed, 7 Jan 2026 12:21:36 +0000 [thread overview]
Message-ID: <20260107122143.93810-7-donald.hunter@gmail.com> (raw)
In-Reply-To: <20260107122143.93810-1-donald.hunter@gmail.com>
Refactor to avoid using global variables to fix the following pylint
issues:
- invalid-name
- global-statement
- global-variable-not-assigned
Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
---
tools/net/ynl/pyynl/lib/nlspec.py | 16 +++++++---------
tools/net/ynl/pyynl/lib/ynl.py | 24 ++++++++++--------------
2 files changed, 17 insertions(+), 23 deletions(-)
diff --git a/tools/net/ynl/pyynl/lib/nlspec.py b/tools/net/ynl/pyynl/lib/nlspec.py
index f3173146b64b..5cc10e654ed6 100644
--- a/tools/net/ynl/pyynl/lib/nlspec.py
+++ b/tools/net/ynl/pyynl/lib/nlspec.py
@@ -13,10 +13,6 @@ import os
import yaml as pyyaml
-# To be loaded dynamically as needed
-jsonschema = None
-
-
class SpecException(Exception):
"""Netlink spec exception.
"""
@@ -439,6 +435,10 @@ class SpecFamily(SpecElement):
mcast_groups dict of all multicast groups (index by name)
kernel_family dict of kernel family attributes
"""
+
+ # To be loaded dynamically as needed
+ jsonschema = None
+
def __init__(self, spec_path, schema_path=None, exclude_ops=None):
with open(spec_path, "r", encoding='utf-8') as stream:
prefix = '# SPDX-License-Identifier: '
@@ -463,15 +463,13 @@ class SpecFamily(SpecElement):
if schema_path is None:
schema_path = os.path.dirname(os.path.dirname(spec_path)) + f'/{self.proto}.yaml'
if schema_path:
- global jsonschema
-
with open(schema_path, "r", encoding='utf-8') as stream:
schema = pyyaml.safe_load(stream)
- if jsonschema is None:
- jsonschema = importlib.import_module("jsonschema")
+ if self.jsonschema is None:
+ self.jsonschema = importlib.import_module("jsonschema")
- jsonschema.validate(self.yaml, schema)
+ self.jsonschema.validate(self.yaml, schema)
self.attr_sets = collections.OrderedDict()
self.sub_msgs = collections.OrderedDict()
diff --git a/tools/net/ynl/pyynl/lib/ynl.py b/tools/net/ynl/pyynl/lib/ynl.py
index 2ad954f885f3..0b7dd2a3c76d 100644
--- a/tools/net/ynl/pyynl/lib/ynl.py
+++ b/tools/net/ynl/pyynl/lib/ynl.py
@@ -320,9 +320,6 @@ class NlMsgs:
yield from self.msgs
-genl_family_name_to_id = None
-
-
def _genl_msg(nl_type, nl_flags, genl_cmd, genl_version, seq=None):
# we prepend length in _genl_msg_finalize()
if seq is None:
@@ -338,6 +335,8 @@ def _genl_msg_finalize(msg):
# pylint: disable=too-many-nested-blocks
def _genl_load_families():
+ genl_family_name_to_id = {}
+
with socket.socket(socket.AF_NETLINK, socket.SOCK_RAW, Netlink.NETLINK_GENERIC) as sock:
sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_CAP_ACK, 1)
@@ -348,18 +347,14 @@ def _genl_load_families():
sock.send(msg, 0)
- global genl_family_name_to_id
- genl_family_name_to_id = dict()
-
while True:
reply = sock.recv(128 * 1024)
nms = NlMsgs(reply)
for nl_msg in nms:
if nl_msg.error:
- print("Netlink error:", nl_msg.error)
- return
+ raise YnlException(f"Netlink error: {nl_msg.error}")
if nl_msg.done:
- return
+ return genl_family_name_to_id
gm = GenlMsg(nl_msg)
fam = {}
@@ -439,15 +434,16 @@ class NetlinkProtocol:
class GenlProtocol(NetlinkProtocol):
+ genl_family_name_to_id = None
+
def __init__(self, family_name):
super().__init__(family_name, Netlink.NETLINK_GENERIC)
- global genl_family_name_to_id
- if genl_family_name_to_id is None:
- _genl_load_families()
+ if self.genl_family_name_to_id is None:
+ self.genl_family_name_to_id = _genl_load_families()
- self.genl_family = genl_family_name_to_id[family_name]
- self.family_id = genl_family_name_to_id[family_name]['id']
+ self.genl_family = self.genl_family_name_to_id[family_name]
+ self.family_id = self.genl_family_name_to_id[family_name]['id']
def message(self, flags, command, version, seq=None):
nlmsg = self._message(self.family_id, flags, seq)
--
2.52.0
next prev parent reply other threads:[~2026-01-07 12:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-07 12:21 [PATCH net-next v1 00/13] tools: ynl: clean up pylint issues Donald Hunter
2026-01-07 12:21 ` [PATCH net-next v1 01/13] tools: ynl: pylint suppressions and docstrings Donald Hunter
2026-01-07 12:21 ` [PATCH net-next v1 02/13] tools: ynl: fix pylint redefinition, encoding errors Donald Hunter
2026-01-07 12:21 ` [PATCH net-next v1 03/13] tools: ynl: fix pylint exception warnings Donald Hunter
2026-01-07 12:21 ` [PATCH net-next v1 04/13] tools: ynl: fix pylint dict, indentation, long lines, uninitialised Donald Hunter
2026-01-07 12:21 ` [PATCH net-next v1 05/13] tools: ynl: fix pylint misc warnings Donald Hunter
2026-01-07 12:21 ` Donald Hunter [this message]
2026-01-07 12:21 ` [PATCH net-next v1 07/13] tools: ynl: fix logic errors reported by pylint Donald Hunter
2026-01-07 12:21 ` [PATCH net-next v1 08/13] tools: ynl: ethtool: fix pylint issues Donald Hunter
2026-01-07 12:21 ` [PATCH net-next v1 09/13] tools: ynl: fix pylint issues in ynl_gen_rst Donald Hunter
2026-01-07 12:21 ` [PATCH net-next v1 10/13] tools: ynl-gen-c: suppress unhelpful pylint messages Donald Hunter
2026-01-07 12:21 ` [PATCH net-next v1 11/13] tools: ynl-gen-c: fix pylint warnings for returns, unused, redefined Donald Hunter
2026-01-07 12:21 ` [PATCH net-next v1 12/13] tools: ynl-gen-c: fix pylint None, type, dict, generators, init Donald Hunter
2026-01-07 12:21 ` [PATCH net-next v1 13/13] tools: ynl-gen-c: Fix remaining pylint warnings Donald Hunter
2026-01-07 16:45 ` Jakub Kicinski
2026-01-07 22:32 ` Donald Hunter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260107122143.93810-7-donald.hunter@gmail.com \
--to=donald.hunter@gmail.com \
--cc=ast@fiberby.net \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gal@nvidia.com \
--cc=horms@kernel.org \
--cc=jacob.e.keller@intel.com \
--cc=jstancek@redhat.com \
--cc=kuba@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=liuhangbin@gmail.com \
--cc=matttbe@kernel.org \
--cc=mchehab+huawei@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=noren@nvidia.com \
--cc=pabeni@redhat.com \
--cc=rubenru09@aol.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.