From 404a68de4f1c26b267a5cae60c8d3e4aeacc88c2 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Mon, 9 Dec 2024 10:02:49 +0100 Subject: [PATCH] Don't mark used function arguments as dummy Fixes lots of issues with ruff 0.8: > RUF052 [*] Local dummy variable `_msg` is accessed This is right -- all these `_msg` are actually being used. Use `type_` and `class_`, follow ruff's recommendation: > help: Prefer using trailing underscores to avoid shadowing a built-in --- src/cockpit/channel.py | 4 ++-- src/cockpit/protocol.py | 10 +++++----- src/cockpit/router.py | 12 ++++++------ test/common/testlib.py | 4 ++-- test/pytest/mocktransport.py | 4 ++-- test/verify/check-packagekit | 12 ++++++------ 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/cockpit/channel.py b/src/cockpit/channel.py index 6f469fe0de6a..7dcabefdd250 100644 --- a/src/cockpit/channel.py +++ b/src/cockpit/channel.py @@ -327,8 +327,8 @@ def send_text(self, data: str) -> bool: """ return self.send_bytes(data.encode()) - def send_json(self, _msg: 'JsonObject | None' = None, **kwargs: JsonValue) -> bool: - pretty = self.json_encoder.encode(create_object(_msg, kwargs)) + '\n' + def send_json(self, msg: 'JsonObject | None' = None, **kwargs: JsonValue) -> bool: + pretty = self.json_encoder.encode(create_object(msg, kwargs)) + '\n' return self.send_text(pretty) def do_pong(self, message): diff --git a/src/cockpit/protocol.py b/src/cockpit/protocol.py index 6671878b9f8c..e2df4275c446 100644 --- a/src/cockpit/protocol.py +++ b/src/cockpit/protocol.py @@ -39,9 +39,9 @@ class CockpitProblem(Exception): """ attrs: JsonObject - def __init__(self, problem: str, _msg: 'JsonObject | None' = None, **kwargs: JsonValue) -> None: + def __init__(self, problem: str, msg: 'JsonObject | None' = None, **kwargs: JsonValue) -> None: kwargs['problem'] = problem - self.attrs = create_object(_msg, kwargs) + self.attrs = create_object(msg, kwargs) super().__init__(get_str(self.attrs, 'message', problem)) def get_attrs(self) -> JsonObject: @@ -179,10 +179,10 @@ def write_channel_data(self, channel: str, payload: bytes) -> None: else: logger.debug('cannot write to closed transport') - def write_control(self, _msg: 'JsonObject | None' = None, **kwargs: JsonValue) -> None: + def write_control(self, msg: 'JsonObject | None' = None, **kwargs: JsonValue) -> None: """Write a control message. See jsonutil.create_object() for details.""" - logger.debug('sending control message %r %r', _msg, kwargs) - pretty = json.dumps(create_object(_msg, kwargs), indent=2) + '\n' + logger.debug('sending control message %r %r', msg, kwargs) + pretty = json.dumps(create_object(msg, kwargs), indent=2) + '\n' self.write_channel_data('', pretty.encode()) def data_received(self, data: bytes) -> None: diff --git a/src/cockpit/router.py b/src/cockpit/router.py index dda836fc1011..50429c463c5a 100644 --- a/src/cockpit/router.py +++ b/src/cockpit/router.py @@ -94,15 +94,15 @@ def send_channel_data(self, channel: str, data: bytes) -> None: self.router.write_channel_data(channel, data) def send_channel_control( - self, channel: str, command: str, _msg: 'JsonObject | None', **kwargs: JsonValue + self, channel: str, command: str, msg: 'JsonObject | None', **kwargs: JsonValue ) -> None: - self.router.write_control(_msg, channel=channel, command=command, **kwargs) + self.router.write_control(msg, channel=channel, command=command, **kwargs) if command == 'close': self.router.endpoints[self].remove(channel) self.router.drop_channel(channel) - def shutdown_endpoint(self, _msg: 'JsonObject | None' = None, **kwargs: JsonValue) -> None: - self.router.shutdown_endpoint(self, _msg, **kwargs) + def shutdown_endpoint(self, msg: 'JsonObject | None' = None, **kwargs: JsonValue) -> None: + self.router.shutdown_endpoint(self, msg, **kwargs) class RoutingError(CockpitProblem): @@ -168,11 +168,11 @@ def add_endpoint(self, endpoint: Endpoint) -> None: self.endpoints[endpoint] = set() self.no_endpoints.clear() - def shutdown_endpoint(self, endpoint: Endpoint, _msg: 'JsonObject | None' = None, **kwargs: JsonValue) -> None: + def shutdown_endpoint(self, endpoint: Endpoint, msg: 'JsonObject | None' = None, **kwargs: JsonValue) -> None: channels = self.endpoints.pop(endpoint) logger.debug('shutdown_endpoint(%s, %s) will close %s', endpoint, kwargs, channels) for channel in channels: - self.write_control(_msg, command='close', channel=channel, **kwargs) + self.write_control(msg, command='close', channel=channel, **kwargs) self.drop_channel(channel) if not self.endpoints: diff --git a/test/common/testlib.py b/test/common/testlib.py index 3c7f25bb31b5..c3334ad5941c 100644 --- a/test/common/testlib.py +++ b/test/common/testlib.py @@ -2489,13 +2489,13 @@ def jsquote(js: object) -> str: return json.dumps(js) -def get_decorator(method: object, _class: object, name: str, default: Any = None) -> Any: +def get_decorator(method: object, class_: object, name: str, default: Any = None) -> Any: """Get decorator value of a test method or its class Return None if the decorator was not set. """ attr = "_testlib__" + name - return getattr(method, attr, getattr(_class, attr, default)) + return getattr(method, attr, getattr(class_, attr, default)) ########################### diff --git a/test/pytest/mocktransport.py b/test/pytest/mocktransport.py index ed2c6f7219ca..dc454c407ba8 100644 --- a/test/pytest/mocktransport.py +++ b/test/pytest/mocktransport.py @@ -17,10 +17,10 @@ async def assert_empty(self): await asyncio.sleep(0.1) assert self.queue.qsize() == 0 - def send_json(self, _channel: str, **kwargs) -> None: + def send_json(self, channel_: str, **kwargs) -> None: # max_read_size is one of our special keys which uses underscores msg = {k.replace('_', '-') if k != "max_read_size" else k: v for k, v in kwargs.items()} - self.send_data(_channel, json.dumps(msg).encode('ascii')) + self.send_data(channel_, json.dumps(msg).encode('ascii')) def send_data(self, channel: str, data: bytes) -> None: msg = channel.encode('ascii') + b'\n' + data diff --git a/test/verify/check-packagekit b/test/verify/check-packagekit index 46ad1be4297f..861fbd0d82d0 100755 --- a/test/verify/check-packagekit +++ b/test/verify/check-packagekit @@ -1425,19 +1425,19 @@ class TestAutoUpdates(NoSubManCase): else: raise NotImplementedError(self.backend) - def assertTypeDnf(_type): - if _type == "all": + def assertTypeDnf(type_): + if type_ == "all": match = '= default' - elif _type == "security": + elif type_ == "security": match = '= security' else: - raise ValueError(_type) + raise ValueError(type_) self.assertIn(match, m.execute(f"grep upgrade_type {self.config}")) - def assertType(_type): + def assertType(type_): if "dnf" in self.backend: - assertTypeDnf(_type) + assertTypeDnf(type_) else: raise NotImplementedError(self.backend)