smell: move type checks to use isinstance.

This commit is contained in:
Romain Dorgueil
2018-08-11 07:08:35 +02:00
parent 7ae1fa82f7
commit 349f999d00
2 changed files with 3 additions and 3 deletions

View File

@ -7,7 +7,7 @@ from bonobo.errors import ValidationError
def to_bool(s):
if s is None:
return False
if type(s) is bool:
if isinstance(s, bool):
return s
if len(s):
if s.lower() in ('f', 'false', 'n', 'no', '0'):

View File

@ -125,13 +125,13 @@ def BagType(typename, fields, *, verbose=False, module=None):
# message or automatically replace the field name with a valid name.
attrs = tuple(map(_uniquify(_make_valid_attr_name), fields))
if type(fields) is str:
if isinstance(fields, str):
raise TypeError('BagType does not support providing fields as a string.')
fields = list(map(str, fields))
typename = str(typename)
for i, name in enumerate([typename] + fields):
if type(name) is not str:
if not isinstance(name, str):
raise TypeError('Type names and field names must be strings, got {name!r}'.format(name=name))
if not i:
if not name.isidentifier():