smell: move type checks to use isinstance.
This commit is contained in:
@ -7,7 +7,7 @@ from bonobo.errors import ValidationError
|
|||||||
def to_bool(s):
|
def to_bool(s):
|
||||||
if s is None:
|
if s is None:
|
||||||
return False
|
return False
|
||||||
if type(s) is bool:
|
if isinstance(s, bool):
|
||||||
return s
|
return s
|
||||||
if len(s):
|
if len(s):
|
||||||
if s.lower() in ('f', 'false', 'n', 'no', '0'):
|
if s.lower() in ('f', 'false', 'n', 'no', '0'):
|
||||||
|
|||||||
@ -125,13 +125,13 @@ def BagType(typename, fields, *, verbose=False, module=None):
|
|||||||
# message or automatically replace the field name with a valid name.
|
# message or automatically replace the field name with a valid name.
|
||||||
|
|
||||||
attrs = tuple(map(_uniquify(_make_valid_attr_name), fields))
|
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.')
|
raise TypeError('BagType does not support providing fields as a string.')
|
||||||
fields = list(map(str, fields))
|
fields = list(map(str, fields))
|
||||||
typename = str(typename)
|
typename = str(typename)
|
||||||
|
|
||||||
for i, name in enumerate([typename] + fields):
|
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))
|
raise TypeError('Type names and field names must be strings, got {name!r}'.format(name=name))
|
||||||
if not i:
|
if not i:
|
||||||
if not name.isidentifier():
|
if not name.isidentifier():
|
||||||
|
|||||||
Reference in New Issue
Block a user