Advertisement
rfmonk

operator_typechecking.py

Jan 16th, 2014
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. from operator import *
  5.  
  6.  
  7. class NoType(object):
  8.     """Supports none of the type APIs"""
  9.  
  10.  
  11. class MultiType(object):
  12.     """Supports multiple type APIs"""
  13.  
  14.     def __len__(self):
  15.         return 0
  16.  
  17.     def __getitem__(self, name):
  18.         return 'mapping'
  19.  
  20.     def __int__(self):
  21.         return 0
  22.  
  23. o = NoType()
  24. t = MultiType()
  25.  
  26. for func in (isMappingType, isNumberType, isSequenceType):
  27.     print '%s(o):' % func.__name__, func(o)
  28.     print '%s(t):' % func.__name__, func(t)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement