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

make this one better #13

@GreatBahram

Description

@GreatBahram

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions