Share

Python typechecker

Tracker: Bugs

5 'Number' does not work properly - ID: 2404537
Last Update: Comment added ( tildebis )

Hello,
I am using typecheck 0.3.5
Python 2.5
Linux Ubuntu 8.10

I tried this example:

import typecheck
from typecheck import accepts
from typecheck.typeclasses import String, Number

@accepts(Number)
def f(a):
print a

if __name__ == "__main__":
f("error")

instead of getting a type exception the function is executed successfully.

Cheers
Tiago


Coutinho ( tiagocoutinho ) - 2008-12-07 21:50

5

Open

None

Collin Winter

Utility classes

None

Public


Comment ( 1 )




Date: 2009-01-04 15:46
Sender: tildebis

Hi,
I have found a way to solve this.
I'm not sure it does not add another bug somewhere else but
it works for me.
In the file typeclasses.py, I have changed this:

### Number
####################################################

_numbers = [int, float, complex, long, bool]
try:
from decimal import Decimal
_numbers.append(Decimal)
del Decimal
except ImportError:
pass
del _numbers

to this:

from typecheck import IsOneOf
### Number
####################################################

try:
from decimal import Decimal
Number = IsOneOf(int, float, long, complex, Decimal)
del Decimal
except ImportError:
Number = IsOneOf(int, float, long, complex)

I will do the same for String, etc.

Regards,
Marc.


Log in to comment.

Attached File

No Files Currently Attached

Change

No changes have been made to this artifact.