Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

make this one better #13

Open
GreatBahram opened this issue May 17, 2019 · 0 comments
Open

make this one better #13

GreatBahram opened this issue May 17, 2019 · 0 comments

Comments

@GreatBahram
Copy link

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)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant