Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: selftests: clean up tools/testing/selftests/net/lib/py/utils.py

This patch improves the utils.py module by removing unused imports
(errno, random), simplifying the fd_read_timeout() function by
eliminating unnecessary else clause, and cleaning up code style in the
defer class constructor.

Additionally, it renames the parameter in rand_port() from 'type' to
'stype' to avoid shadowing the built-in Python name 'type', improving
code clarity and preventing potential issues.

These changes enhance code readability and maintainability without
affecting functionality.

Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250901-fix-v1-1-df0abb67481e@debian.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Breno Leitao and committed by
Jakub Kicinski
23313771 d250f14f

+3 -8
+3 -8
tools/testing/selftests/net/lib/py/utils.py
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 3 - import errno 4 3 import json as _json 5 4 import os 6 - import random 7 5 import re 8 6 import select 9 7 import socket ··· 19 21 rlist, _, _ = select.select([fd], [], [], timeout) 20 22 if rlist: 21 23 return os.read(fd, 1024) 22 - else: 23 - raise TimeoutError("Timeout waiting for fd read") 24 + raise TimeoutError("Timeout waiting for fd read") 24 25 25 26 26 27 class cmd: ··· 135 138 136 139 class defer: 137 140 def __init__(self, func, *args, **kwargs): 138 - global global_defer_queue 139 - 140 141 if not callable(func): 141 142 raise Exception("defer created with un-callable object, did you call the function instead of passing its name?") 142 143 ··· 222 227 return cmd_obj 223 228 224 229 225 - def rand_port(type=socket.SOCK_STREAM): 230 + def rand_port(stype=socket.SOCK_STREAM): 226 231 """ 227 232 Get a random unprivileged port. 228 233 """ 229 - with socket.socket(socket.AF_INET6, type) as s: 234 + with socket.socket(socket.AF_INET6, stype) as s: 230 235 s.bind(("", 0)) 231 236 return s.getsockname()[1] 232 237