PEP8 remove direct type comparisons
Fixes bug #910763 According to PEP8, - Object type comparisons should always use isinstance() instead of comparing types directly. Yes: if isinstance(obj, int): No: if type(obj) is type(1): When checking if an object is a string, keep in mind that it might be a unicode string too! In Python 2.3, str and unicode have a common base class, basestring, so you can do: if isinstance(obj, basestring): Change-Id: I7c0fdecf99872f5b8f72b2c2ed4f5c539c33def1
This commit is contained in:
@@ -366,7 +366,7 @@ class XMLDictSerializer(DictSerializer):
|
||||
result.setAttribute('xmlns', xmlns)
|
||||
|
||||
#TODO(bcwaldon): accomplish this without a type-check
|
||||
if type(data) is list:
|
||||
if isinstance(data, list):
|
||||
collections = metadata.get('list_collections', {})
|
||||
if nodename in collections:
|
||||
metadata = collections[nodename]
|
||||
@@ -385,7 +385,7 @@ class XMLDictSerializer(DictSerializer):
|
||||
node = self._to_xml_node(doc, metadata, singular, item)
|
||||
result.appendChild(node)
|
||||
#TODO(bcwaldon): accomplish this without a type-check
|
||||
elif type(data) is dict:
|
||||
elif isinstance(data, dict):
|
||||
collections = metadata.get('dict_collections', {})
|
||||
if nodename in collections:
|
||||
metadata = collections[nodename]
|
||||
@@ -573,7 +573,7 @@ class Resource(wsgi.Application):
|
||||
LOG.info(_("HTTP exception thrown: %s"), unicode(ex))
|
||||
action_result = Fault(ex)
|
||||
|
||||
if type(action_result) is dict or action_result is None:
|
||||
if isinstance(action_result, dict) or action_result is None:
|
||||
response = self.serializer.serialize(request,
|
||||
action_result,
|
||||
accept,
|
||||
|
Reference in New Issue
Block a user