From 13a16fa331fd00b07814dc40806bef3fbc60ea88 Mon Sep 17 00:00:00 2001 From: PIG208 <359101898@qq.com> Date: Tue, 27 Jul 2021 01:33:26 +0800 Subject: [PATCH] typing: Avoid scoped redefinition of different types. Mypy doesn't allow redefinition of a variable using a different type within the same scope. https://github.com/python/mypy/issues/1174 --- corporate/tests/test_stripe.py | 10 +++++----- zerver/tests/test_decorators.py | 10 ++++++---- zerver/tests/test_users.py | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py index 12a5b5b4be4ac4..139cb2b0f3415a 100644 --- a/corporate/tests/test_stripe.py +++ b/corporate/tests/test_stripe.py @@ -487,9 +487,9 @@ def raise_invalid_request_error() -> None: raise stripe.error.InvalidRequestError("message", "param", "code", json_body={}) with self.assertLogs("corporate.stripe", "ERROR") as error_log: - with self.assertRaises(BillingError) as context: + with self.assertRaises(BillingError) as billing_context: raise_invalid_request_error() - self.assertEqual("other stripe error", context.exception.error_description) + self.assertEqual("other stripe error", billing_context.exception.error_description) self.assertEqual( error_log.output, ["ERROR:corporate.stripe:Stripe error: None None None None"] ) @@ -503,10 +503,10 @@ def raise_card_error() -> None: ) with self.assertLogs("corporate.stripe", "INFO") as info_log: - with self.assertRaises(StripeCardError) as context: + with self.assertRaises(StripeCardError) as card_context: raise_card_error() - self.assertIn("not a valid credit card", str(context.exception)) - self.assertEqual("card error", context.exception.error_description) + self.assertIn("not a valid credit card", str(card_context.exception)) + self.assertEqual("card error", card_context.exception.error_description) self.assertEqual( info_log.output, ["INFO:corporate.stripe:Stripe card error: None None None None"] ) diff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.py index 2c913d1bfb2ea6..8a0c5dfd9b78da 100644 --- a/zerver/tests/test_decorators.py +++ b/zerver/tests/test_decorators.py @@ -179,14 +179,16 @@ def get_total( self.assertEqual(str(cm.exception), "Bad value for 'numbers': bad_value") request.POST["numbers"] = orjson.dumps("{fun: unfun}").decode() - with self.assertRaises(JsonableError) as cm: + with self.assertRaises(JsonableError) as jsonable_error_cm: get_total(request) - self.assertEqual(str(cm.exception), "Bad value for 'numbers': \"{fun: unfun}\"") + self.assertEqual( + str(jsonable_error_cm.exception), "Bad value for 'numbers': \"{fun: unfun}\"" + ) request.POST["numbers"] = orjson.dumps([2, 3, 5, 8, 13, 21]).decode() - with self.assertRaises(JsonableError) as cm: + with self.assertRaises(JsonableError) as jsonable_error_cm: get_total(request) - self.assertEqual(str(cm.exception), "13 is an unlucky number!") + self.assertEqual(str(jsonable_error_cm.exception), "13 is an unlucky number!") request.POST["numbers"] = orjson.dumps([1, 2, 3, 4, 5, 6]).decode() result = get_total(request) diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.py index dd164c765effa4..6c22473d0d624e 100644 --- a/zerver/tests/test_users.py +++ b/zerver/tests/test_users.py @@ -295,7 +295,7 @@ def test_admin_api_hide_emails(self) -> None: "zerver.lib.events.request_event_queue", return_value=None ) as mock_request_event_queue: with self.assertRaises(JsonableError): - result = do_events_register(user, get_client("website"), client_gravatar=True) + do_events_register(user, get_client("website"), client_gravatar=True) self.assertEqual(mock_request_event_queue.call_args_list[0][0][3], True) #############################################################