[Bank] Raise TypeError when passing a non-int transaction amount (#1976)

* Raise TypeError when passing a non-int bank amount

* Add a test

* Add some full stops
This commit is contained in:
Toby Harradine
2018-08-09 22:13:31 +10:00
committed by GitHub
parent 16d0f54d8f
commit 652ceba845
2 changed files with 25 additions and 1 deletions

View File

@@ -214,8 +214,12 @@ async def withdraw_credits(member: discord.Member, amount: int) -> int:
ValueError
If the withdrawal amount is invalid or if the account has insufficient
funds.
TypeError
If the withdrawal amount is not an `int`.
"""
if not isinstance(amount, int):
raise TypeError("Withdrawal amount must be of type int, not {}.".format(type(amount)))
if _invalid_amount(amount):
raise ValueError("Invalid withdrawal amount {} < 0".format(amount))
@@ -245,8 +249,12 @@ async def deposit_credits(member: discord.Member, amount: int) -> int:
------
ValueError
If the deposit amount is invalid.
TypeError
If the deposit amount is not an `int`.
"""
if not isinstance(amount, int):
raise TypeError("Deposit amount must be of type int, not {}.".format(type(amount)))
if _invalid_amount(amount):
raise ValueError("Invalid deposit amount {} <= 0".format(amount))
@@ -269,14 +277,18 @@ async def transfer_credits(from_: discord.Member, to: discord.Member, amount: in
Returns
-------
int
The new balance.
The new balance of the member gaining credits.
Raises
------
ValueError
If the amount is invalid or if ``from_`` has insufficient funds.
TypeError
If the amount is not an `int`.
"""
if not isinstance(amount, int):
raise TypeError("Transfer amount must be of type int, not {}.".format(type(amount)))
if _invalid_amount(amount):
raise ValueError("Invalid transfer amount {} <= 0".format(amount))