Clean up type comparisons.

This commit is contained in:
Florian Bruhin 2015-08-07 23:10:22 +02:00
parent 03d8a6c05d
commit 18125c7d1f
1 changed files with 4 additions and 3 deletions

View File

@ -983,15 +983,16 @@ def _idval(val, argname, idx, idfn):
except ImportError: except ImportError:
# Only available in Python 3.4+ # Only available in Python 3.4+
enum = None enum = None
# The type of re.compile objects is not exposed in Python.
RegexType = type(re.compile(''))
if isinstance(val, (float, int, str, bool, NoneType)): if isinstance(val, (float, int, str, bool, NoneType)):
return str(val) return str(val)
elif isinstance(val, type(re.compile(''))): elif isinstance(val, RegexType):
# The type of re.compile objects is not exposed in Python.
return val.pattern return val.pattern
elif enum is not None and isinstance(val, enum.Enum): elif enum is not None and isinstance(val, enum.Enum):
return str(val) return str(val)
elif isinstance(val, type) and hasattr(val, '__name__'): elif inspect.isclass(val) and hasattr(val, '__name__'):
return val.__name__ return val.__name__
return str(argname)+str(idx) return str(argname)+str(idx)