is_type(obj, typestr_or_type) verifies if obj is of a certain type. It can take strings or actual python types for the second argument, i.e. 'tuple'<->TupleType. 'all' matches all types. TODO: Should be extended for choosing more than one type.
(obj, typestr_or_type)
| 36 | typestr2type, type2typestr = create_typestr2type_dicts() |
| 37 | |
| 38 | def is_type(obj, typestr_or_type): |
| 39 | """is_type(obj, typestr_or_type) verifies if obj is of a certain type. It |
| 40 | can take strings or actual python types for the second argument, i.e. |
| 41 | 'tuple'<->TupleType. 'all' matches all types. |
| 42 | |
| 43 | TODO: Should be extended for choosing more than one type.""" |
| 44 | if typestr_or_type == "all": |
| 45 | return True |
| 46 | if type(typestr_or_type) == type: |
| 47 | test_type = typestr_or_type |
| 48 | else: |
| 49 | test_type = typestr2type.get(typestr_or_type, False) |
| 50 | if test_type: |
| 51 | return isinstance(obj, test_type) |
| 52 | return False |
| 53 | |
| 54 | def show_hidden(str, show_all=False): |
| 55 | """Return true for strings starting with single _ if show_all is true.""" |