This repository was archived by the owner on Sep 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
This repository was archived by the owner on Sep 22, 2022. It is now read-only.
make this one better #13
Copy link
Copy link
Open
Description
persiantools/persiantools/utils.py
Lines 14 to 32 in a88112b
if isinstance(value, int): | |
return value | |
if not isinstance(value, float): | |
try: | |
value = value.__int__() | |
except AttributeError: | |
pass | |
else: | |
if isinstance(value, int): | |
return value | |
raise TypeError( | |
'__int__ returned non-int (type %s)' % type(value).__name__) | |
raise TypeError( | |
'an integer is required (got type %s)' % type(value).__name__) | |
raise TypeError('integer argument expected, got float') |
isintance
takes a tuple of classes for the second argument. So you could basicly do something like this:
if not isinstance(value, (int, float)):
raise TypeError('value should int or float object')
return int(value)
Metadata
Metadata
Assignees
Labels
No labels