Skip to content

Commit

Permalink
Don't mark used function arguments as dummy
Browse files Browse the repository at this point in the history
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
  • Loading branch information
martinpitt committed Dec 9, 2024
1 parent 35192bd commit 404a68d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/cockpit/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions src/cockpit/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions src/cockpit/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions test/common/testlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


###########################
Expand Down
4 changes: 2 additions & 2 deletions test/pytest/mocktransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions test/verify/check-packagekit
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 404a68d

Please sign in to comment.