[Types-sig] Type declarations

Paul Prescod paulp@ActiveState.com
Thu, 15 Mar 2001 22:19:42 -0800


Here are some type declarations for the types used in the example:

def _ismapping(obj):
    if type(obj)==types.InstanceType: 
        return (hasattr(obj, "__getitem__")
                and hasattr(obj, "items"))
    else:
        return operator.isMappingType(obj)

IMapping = Interface(name = "IMapping", 
		doc = "Mapping from keys to values", 
		testfunc = _ismapping)

IString=Interface(name = "IString", 
    		doc = "Unicode or 8-bit string",
 testfunc = lambda obj: type(obj) in 
			(types.StringType, types.UnicodeType))

IStrictBoolean = Interface(name = "IStrictBoolean", 
		doc = "0 or 1 value", 
	testfunc = lambda obj: obj in (0, 1))        


-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.activestate.com/pythoncookbook