[Python-3000] Type Comparisons with Godel Numbers

Jim Jewett jimjjewett at gmail.com
Mon Apr 24 01:55:56 CEST 2006


On 4/21/06, Giovanni Bajo <rasky at develer.com> wrote:

> Another (similar) way would be to let the user pay for the high typechecking
> price in normal cases *but* provide a list[int] class, which is a list
> decorated with typechecks on modification operations. We could have
> list[int|float]() to construct a list which can hold either ints or floats.

Remember that the current thought is "annotations" rather than "type
specifiers", with any actual verication done by a separate decorator.

If you really need to ensure list[int], then you can declare a
subclass of list that verifies each element on instance creation or
modification, and then use your decorator to replace any incoming
sequence with a (possibly newly created) instance of this subclass.

There will be some wasted work if another framework uses a different
adapter class to say the same thing, but that should be the sort of
"major boundary" where it is reasonable to verify things.  If you pass
an object out to code that doesn't care, they won't see any extra
costs (unless they special case CheckExact).  What they pass back may
even still be the same object, and if not ... you can always remove
the decorator for speed.

-jJ


More information about the Python-3000 mailing list