Skip to content

Commit 8330b5c

Browse files
committed
typing: Avoid scoped redefinition of different types.
Mypy doesn't allow redefinition of a variable using a different type within the same scope. python/mypy#1174
1 parent dec28f5 commit 8330b5c

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

corporate/tests/test_stripe.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,9 @@ def raise_invalid_request_error() -> None:
487487
raise stripe.error.InvalidRequestError("message", "param", "code", json_body={})
488488

489489
with self.assertLogs("corporate.stripe", "ERROR") as error_log:
490-
with self.assertRaises(BillingError) as context:
490+
with self.assertRaises(BillingError) as billing_context:
491491
raise_invalid_request_error()
492-
self.assertEqual("other stripe error", context.exception.error_description)
492+
self.assertEqual("other stripe error", billing_context.exception.error_description)
493493
self.assertEqual(
494494
error_log.output, ["ERROR:corporate.stripe:Stripe error: None None None None"]
495495
)
@@ -503,10 +503,10 @@ def raise_card_error() -> None:
503503
)
504504

505505
with self.assertLogs("corporate.stripe", "INFO") as info_log:
506-
with self.assertRaises(StripeCardError) as context:
506+
with self.assertRaises(StripeCardError) as card_context:
507507
raise_card_error()
508-
self.assertIn("not a valid credit card", str(context.exception))
509-
self.assertEqual("card error", context.exception.error_description)
508+
self.assertIn("not a valid credit card", str(card_context.exception))
509+
self.assertEqual("card error", card_context.exception.error_description)
510510
self.assertEqual(
511511
info_log.output, ["INFO:corporate.stripe:Stripe card error: None None None None"]
512512
)

zerver/tests/test_decorators.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,16 @@ def get_total(
179179
self.assertEqual(str(cm.exception), "Bad value for 'numbers': bad_value")
180180

181181
request.POST["numbers"] = orjson.dumps("{fun: unfun}").decode()
182-
with self.assertRaises(JsonableError) as cm:
182+
with self.assertRaises(JsonableError) as jsonable_error_cm:
183183
get_total(request)
184-
self.assertEqual(str(cm.exception), "Bad value for 'numbers': \"{fun: unfun}\"")
184+
self.assertEqual(
185+
str(jsonable_error_cm.exception), "Bad value for 'numbers': \"{fun: unfun}\""
186+
)
185187

186188
request.POST["numbers"] = orjson.dumps([2, 3, 5, 8, 13, 21]).decode()
187-
with self.assertRaises(JsonableError) as cm:
189+
with self.assertRaises(JsonableError) as jsonable_error_cm:
188190
get_total(request)
189-
self.assertEqual(str(cm.exception), "13 is an unlucky number!")
191+
self.assertEqual(str(jsonable_error_cm.exception), "13 is an unlucky number!")
190192

191193
request.POST["numbers"] = orjson.dumps([1, 2, 3, 4, 5, 6]).decode()
192194
result = get_total(request)

zerver/tests/test_users.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def test_admin_api_hide_emails(self) -> None:
295295
"zerver.lib.events.request_event_queue", return_value=None
296296
) as mock_request_event_queue:
297297
with self.assertRaises(JsonableError):
298-
result = do_events_register(user, get_client("website"), client_gravatar=True)
298+
do_events_register(user, get_client("website"), client_gravatar=True)
299299
self.assertEqual(mock_request_event_queue.call_args_list[0][0][3], True)
300300

301301
#############################################################

0 commit comments

Comments
 (0)