mirror of https://github.com/zulip/zulip.git
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>
This commit is contained in:
parent
553f268b04
commit
d748ec8d52
|
@ -156,7 +156,7 @@ IGNORED_PHRASES = [
|
||||||
|
|
||||||
# Sort regexes in descending order of their lengths. As a result, the
|
# Sort regexes in descending order of their lengths. As a result, the
|
||||||
# longer phrases will be ignored first.
|
# 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
|
# Compile regexes to improve performance. This also extracts the
|
||||||
# text using BeautifulSoup and then removes extra whitespaces from
|
# text using BeautifulSoup and then removes extra whitespaces from
|
||||||
|
|
|
@ -388,7 +388,7 @@ def main() -> None:
|
||||||
if not options.no_cov_cleanup:
|
if not options.no_cov_cleanup:
|
||||||
import atexit
|
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()
|
cov.start()
|
||||||
if options.profile:
|
if options.profile:
|
||||||
import cProfile
|
import cProfile
|
||||||
|
|
|
@ -42,8 +42,8 @@ class StateHandler:
|
||||||
|
|
||||||
def __init__(self, user_profile: UserProfile) -> None:
|
def __init__(self, user_profile: UserProfile) -> None:
|
||||||
self.user_profile = user_profile
|
self.user_profile = user_profile
|
||||||
self.marshal: Callable[[object], str] = lambda obj: json.dumps(obj)
|
self.marshal: Callable[[object], str] = json.dumps
|
||||||
self.demarshal: Callable[[str], object] = lambda obj: json.loads(obj)
|
self.demarshal: Callable[[str], object] = json.loads
|
||||||
|
|
||||||
def get(self, key: str) -> object:
|
def get(self, key: str) -> object:
|
||||||
return self.demarshal(get_bot_storage(self.user_profile, key))
|
return self.demarshal(get_bot_storage(self.user_profile, key))
|
||||||
|
|
|
@ -90,12 +90,12 @@ cache_fillers: Dict[
|
||||||
] = {
|
] = {
|
||||||
"user": (get_users, user_cache_items, 3600 * 24 * 7, 10000),
|
"user": (get_users, user_cache_items, 3600 * 24 * 7, 10000),
|
||||||
"client": (
|
"client": (
|
||||||
lambda: Client.objects.all(),
|
Client.objects.all,
|
||||||
client_cache_items,
|
client_cache_items,
|
||||||
3600 * 24 * 7,
|
3600 * 24 * 7,
|
||||||
10000,
|
10000,
|
||||||
),
|
),
|
||||||
"session": (lambda: Session.objects.all(), session_cache_items, 3600 * 24 * 7, 10000),
|
"session": (Session.objects.all, session_cache_items, 3600 * 24 * 7, 10000),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1971,9 +1971,7 @@ class ZulipTestCase(ZulipTestCaseMixin, TestCase):
|
||||||
# Some code might call process_notification using keyword arguments,
|
# Some code might call process_notification using keyword arguments,
|
||||||
# so mypy doesn't allow assigning lst.append to process_notification
|
# so mypy doesn't allow assigning lst.append to process_notification
|
||||||
# So explicitly change parameter name to 'notice' to work around this problem
|
# So explicitly change parameter name to 'notice' to work around this problem
|
||||||
with mock.patch(
|
with mock.patch("zerver.tornado.event_queue.process_notification", lst.append):
|
||||||
"zerver.tornado.event_queue.process_notification", lambda notice: lst.append(notice)
|
|
||||||
):
|
|
||||||
# Some `send_event` calls need to be executed only after the current transaction
|
# 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 (using `on_commit` hooks). Because the transaction in Django tests never
|
||||||
# commits (rather, gets rolled back after the test completes), such events would
|
# commits (rather, gets rolled back after the test completes), such events would
|
||||||
|
|
|
@ -3345,7 +3345,7 @@ class NormalActionsTest(BaseAction):
|
||||||
base = "/user_uploads/"
|
base = "/user_uploads/"
|
||||||
self.assertEqual(base, url[: len(base)])
|
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])
|
check_attachment_add("events[0]", events[0])
|
||||||
self.assertEqual(events[0]["upload_space_used"], 6)
|
self.assertEqual(events[0]["upload_space_used"], 6)
|
||||||
|
@ -3481,21 +3481,21 @@ class NormalActionsTest(BaseAction):
|
||||||
|
|
||||||
def test_restart_event(self) -> None:
|
def test_restart_event(self) -> None:
|
||||||
self.verify_action(
|
self.verify_action(
|
||||||
lambda: send_restart_events(),
|
send_restart_events,
|
||||||
num_events=1,
|
num_events=1,
|
||||||
state_change_expected=False,
|
state_change_expected=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_web_reload_client_event(self) -> None:
|
def test_web_reload_client_event(self) -> None:
|
||||||
self.verify_action(
|
self.verify_action(
|
||||||
lambda: send_web_reload_client_events(),
|
send_web_reload_client_events,
|
||||||
client_is_old=False,
|
client_is_old=False,
|
||||||
num_events=0,
|
num_events=0,
|
||||||
state_change_expected=False,
|
state_change_expected=False,
|
||||||
)
|
)
|
||||||
with self.assertLogs(level="WARNING") as logs:
|
with self.assertLogs(level="WARNING") as logs:
|
||||||
self.verify_action(
|
self.verify_action(
|
||||||
lambda: send_web_reload_client_events(),
|
send_web_reload_client_events,
|
||||||
client_is_old=True,
|
client_is_old=True,
|
||||||
num_events=1,
|
num_events=1,
|
||||||
state_change_expected=False,
|
state_change_expected=False,
|
||||||
|
|
|
@ -76,7 +76,7 @@ class TestSessions(ZulipTestCase):
|
||||||
def test_delete_all_user_sessions(self) -> None:
|
def test_delete_all_user_sessions(self) -> None:
|
||||||
self.do_test_session(
|
self.do_test_session(
|
||||||
self.example_user("hamlet"),
|
self.example_user("hamlet"),
|
||||||
lambda: delete_all_user_sessions(),
|
delete_all_user_sessions,
|
||||||
get_realm("zulip"),
|
get_realm("zulip"),
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
|
@ -90,7 +90,7 @@ class TestSessions(ZulipTestCase):
|
||||||
)
|
)
|
||||||
self.do_test_session(
|
self.do_test_session(
|
||||||
self.lear_user("cordelia"),
|
self.lear_user("cordelia"),
|
||||||
lambda: delete_all_user_sessions(),
|
delete_all_user_sessions,
|
||||||
lear_realm,
|
lear_realm,
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
|
|
|
@ -34,7 +34,7 @@ class TimeoutTestCase(ZulipTestCase):
|
||||||
|
|
||||||
def test_timeout_raises(self) -> None:
|
def test_timeout_raises(self) -> None:
|
||||||
try:
|
try:
|
||||||
timeout(1, lambda: self.something_exceptional())
|
timeout(1, self.something_exceptional)
|
||||||
raise AssertionError("Failed to raise an exception")
|
raise AssertionError("Failed to raise an exception")
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
tb = traceback.format_tb(exc.__traceback__)
|
tb = traceback.format_tb(exc.__traceback__)
|
||||||
|
|
|
@ -9,7 +9,7 @@ from zerver.tornado.handlers import AsyncDjangoHandler
|
||||||
|
|
||||||
def setup_tornado_rabbitmq(queue_client: TornadoQueueClient) -> None: # nocoverage
|
def setup_tornado_rabbitmq(queue_client: TornadoQueueClient) -> None: # nocoverage
|
||||||
# When tornado is shut down, disconnect cleanly from RabbitMQ
|
# 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:
|
def create_tornado_application(*, autoreload: bool = False) -> tornado.web.Application:
|
||||||
|
|
|
@ -73,7 +73,7 @@ class UserGroupRaceConditionTestCase(ZulipTransactionTestCase):
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
for group in self.created_user_groups:
|
for group in self.created_user_groups:
|
||||||
group.delete()
|
group.delete()
|
||||||
transaction.on_commit(lambda: self.created_user_groups.clear())
|
transaction.on_commit(self.created_user_groups.clear)
|
||||||
|
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
|
|
|
@ -683,7 +683,7 @@ class MissedMessageWorker(QueueProcessingWorker):
|
||||||
def start(self) -> None:
|
def start(self) -> None:
|
||||||
with self.cv:
|
with self.cv:
|
||||||
self.stopping = False
|
self.stopping = False
|
||||||
self.worker_thread = threading.Thread(target=lambda: self.work())
|
self.worker_thread = threading.Thread(target=self.work)
|
||||||
self.worker_thread.start()
|
self.worker_thread.start()
|
||||||
super().start()
|
super().start()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue