ruff: Fix PLW0108 Lambda may be unnecessary.

This is a preview rule, not yet enabled by default.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit d748ec8d52)
This commit is contained in:
Anders Kaseorg
2024-02-29 17:56:37 -08:00
committed by Tim Abbott
parent 9eaec853d1
commit e546bc5d26
11 changed files with 14 additions and 16 deletions

View File

@@ -154,7 +154,7 @@ IGNORED_PHRASES = [
# Sort regexes in descending order of their lengths. As a result, the
# longer phrases will be ignored first.
IGNORED_PHRASES.sort(key=lambda regex: len(regex), reverse=True)
IGNORED_PHRASES.sort(key=len, reverse=True)
# Compile regexes to improve performance. This also extracts the
# text using BeautifulSoup and then removes extra whitespaces from

View File

@@ -389,7 +389,7 @@ def main() -> None:
if not options.no_cov_cleanup:
import atexit
atexit.register(lambda: cov.erase()) # Ensure the data file gets cleaned up at the end.
atexit.register(cov.erase) # Ensure the data file gets cleaned up at the end.
cov.start()
if options.profile:
import cProfile

View File

@@ -42,8 +42,8 @@ class StateHandler:
def __init__(self, user_profile: UserProfile) -> None:
self.user_profile = user_profile
self.marshal: Callable[[object], str] = lambda obj: json.dumps(obj)
self.demarshal: Callable[[str], object] = lambda obj: json.loads(obj)
self.marshal: Callable[[object], str] = json.dumps
self.demarshal: Callable[[str], object] = json.loads
def get(self, key: str) -> object:
return self.demarshal(get_bot_storage(self.user_profile, key))

View File

@@ -90,12 +90,12 @@ cache_fillers: Dict[
] = {
"user": (get_users, user_cache_items, 3600 * 24 * 7, 10000),
"client": (
lambda: Client.objects.all(),
Client.objects.all,
client_cache_items,
3600 * 24 * 7,
10000,
),
"session": (lambda: Session.objects.all(), session_cache_items, 3600 * 24 * 7, 10000),
"session": (Session.objects.all, session_cache_items, 3600 * 24 * 7, 10000),
}

View File

@@ -1971,9 +1971,7 @@ class ZulipTestCase(ZulipTestCaseMixin, TestCase):
# Some code might call process_notification using keyword arguments,
# so mypy doesn't allow assigning lst.append to process_notification
# So explicitly change parameter name to 'notice' to work around this problem
with mock.patch(
"zerver.tornado.event_queue.process_notification", lambda notice: lst.append(notice)
):
with mock.patch("zerver.tornado.event_queue.process_notification", lst.append):
# Some `send_event` calls need to be executed only after the current transaction
# commits (using `on_commit` hooks). Because the transaction in Django tests never
# commits (rather, gets rolled back after the test completes), such events would

View File

@@ -3322,7 +3322,7 @@ class NormalActionsTest(BaseAction):
base = "/user_uploads/"
self.assertEqual(base, url[: len(base)])
events = self.verify_action(lambda: do_upload(), num_events=1, state_change_expected=False)
events = self.verify_action(do_upload, num_events=1, state_change_expected=False)
check_attachment_add("events[0]", events[0])
self.assertEqual(events[0]["upload_space_used"], 6)

View File

@@ -76,7 +76,7 @@ class TestSessions(ZulipTestCase):
def test_delete_all_user_sessions(self) -> None:
self.do_test_session(
self.example_user("hamlet"),
lambda: delete_all_user_sessions(),
delete_all_user_sessions,
get_realm("zulip"),
True,
)
@@ -90,7 +90,7 @@ class TestSessions(ZulipTestCase):
)
self.do_test_session(
self.lear_user("cordelia"),
lambda: delete_all_user_sessions(),
delete_all_user_sessions,
lear_realm,
True,
)

View File

@@ -34,7 +34,7 @@ class TimeoutTestCase(ZulipTestCase):
def test_timeout_raises(self) -> None:
try:
timeout(1, lambda: self.something_exceptional())
timeout(1, self.something_exceptional)
raise AssertionError("Failed to raise an exception")
except ValueError as exc:
tb = traceback.format_tb(exc.__traceback__)

View File

@@ -9,7 +9,7 @@ from zerver.tornado.handlers import AsyncDjangoHandler
def setup_tornado_rabbitmq(queue_client: TornadoQueueClient) -> None: # nocoverage
# When tornado is shut down, disconnect cleanly from RabbitMQ
autoreload.add_reload_hook(lambda: queue_client.close())
autoreload.add_reload_hook(queue_client.close)
def create_tornado_application(*, autoreload: bool = False) -> tornado.web.Application:

View File

@@ -73,7 +73,7 @@ class UserGroupRaceConditionTestCase(ZulipTransactionTestCase):
with transaction.atomic():
for group in self.created_user_groups:
group.delete()
transaction.on_commit(lambda: self.created_user_groups.clear())
transaction.on_commit(self.created_user_groups.clear)
super().tearDown()

View File

@@ -666,7 +666,7 @@ class MissedMessageWorker(QueueProcessingWorker):
def start(self) -> None:
with self.cv:
self.stopping = False
self.worker_thread = threading.Thread(target=lambda: self.work())
self.worker_thread = threading.Thread(target=self.work)
self.worker_thread.start()
super().start()