Skip to content

Commit

Permalink
typing: Avoid scoped redefinition of different types.
Browse files Browse the repository at this point in the history
Mypy doesn't allow redefinition of a variable using a different type
within the same scope.
python/mypy#1174
  • Loading branch information
PIG208 committed Jul 26, 2021
1 parent e3bb910 commit 13a16fa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
10 changes: 5 additions & 5 deletions corporate/tests/test_stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)
Expand All @@ -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"]
)
Expand Down
10 changes: 6 additions & 4 deletions zerver/tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion zerver/tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

#############################################################
Expand Down

0 comments on commit 13a16fa

Please sign in to comment.