[Types-sig] Sample declarations

Tim Hochberg tim.hochberg@ieee.org
Tue, 13 Mar 2001 08:03:44 -0700


Paul Prescod writes:
----- Original Message -----
> ############# Basic types ##############
>
> class _number:
>     "Any kind of Number"
>     def __implementedby__(self, obj):
>         try:  # includes appropriate complexes, excludes strings
>               # should I use isNumberType???
>             complex(obj)
>             return 1
>         except TypeError:
>             return 0


This probably isn't what you want since it returns true for strings that
represent complex numbers, such as "1+5j". Perhaps you should use your
complex(obj) == obj trick here as you did for float. On the other hand, that
has the same problems with integers that Guido notes in his email. I see
Guido has now commented on the others ones more thouroughly than I could
have, so I'll leave it at that.

-tim (who went to bed thinking this proposal had vanished without ripple...)