Skip to content
Browse files

Replace type() comparisons with isinstance()

  • Loading branch information...
1 parent 9539206 commit 601653cf20f93a56573610b3616d386b7c1b8f82 @gholms gholms committed Jun 8, 2012
View
2 boto/ec2/connection.py
@@ -2196,7 +2196,7 @@ def authorize_security_group(self, group_name=None,
if to_port is not None:
params['IpPermissions.1.ToPort'] = to_port
if cidr_ip:
- if type(cidr_ip) != list:
+ if not isinstance(cidr_ip, list):
cidr_ip = [cidr_ip]
for i, single_cidr_ip in enumerate(cidr_ip):
params['IpPermissions.1.IpRanges.%d.CidrIp' % (i+1)] = \
View
2 boto/ec2/securitygroup.py
@@ -183,7 +183,7 @@ def authorize(self, ip_protocol=None, from_port=None, to_port=None,
group_id,
src_group_group_id)
if status:
- if type(cidr_ip) != list:
+ if not isinstance(cidr_ip, list):
cidr_ip = [cidr_ip]
for single_cidr_ip in cidr_ip:
self.add_rule(ip_protocol, from_port, to_port, src_group_name,
View
14 boto/emr/connection.py
@@ -139,7 +139,7 @@ def add_jobflow_steps(self, jobflow_id, steps):
:type steps: list(boto.emr.Step)
:param steps: A list of steps to add to the job
"""
- if type(steps) != types.ListType:
+ if not isinstance(steps, types.ListType):
steps = [steps]
params = {}
params['JobFlowId'] = jobflow_id
@@ -162,7 +162,7 @@ def add_instance_groups(self, jobflow_id, instance_groups):
:type instance_groups: list(boto.emr.InstanceGroup)
:param instance_groups: A list of instance groups to add to the job
"""
- if type(instance_groups) != types.ListType:
+ if not isinstance(instance_groups, types.ListType):
instance_groups = [instance_groups]
params = {}
params['JobFlowId'] = jobflow_id
@@ -183,9 +183,9 @@ def modify_instance_groups(self, instance_group_ids, new_sizes):
:type new_sizes: list(int)
:param new_sizes: A list of the new sizes for each instance group
"""
- if type(instance_group_ids) != types.ListType:
+ if not isinstance(instance_group_ids, types.ListType):
instance_group_ids = [instance_group_ids]
- if type(new_sizes) != types.ListType:
+ if not isinstance(new_sizes, types.ListType):
new_sizes = [new_sizes]
instance_groups = zip(instance_group_ids, new_sizes)
@@ -403,7 +403,7 @@ def _build_step_args(self, step):
return step_params
def _build_bootstrap_action_list(self, bootstrap_actions):
- if type(bootstrap_actions) != types.ListType:
+ if not isinstance(bootstrap_actions, types.ListType):
bootstrap_actions = [bootstrap_actions]
params = {}
@@ -413,7 +413,7 @@ def _build_bootstrap_action_list(self, bootstrap_actions):
return params
def _build_step_list(self, steps):
- if type(steps) != types.ListType:
+ if not isinstance(steps, types.ListType):
steps = [steps]
params = {}
@@ -475,7 +475,7 @@ def _build_instance_group_list_args(self, instance_groups):
a comparable dict for use in making a RunJobFlow or AddInstanceGroups
request.
"""
- if type(instance_groups) != types.ListType:
+ if not isinstance(instance_groups, types.ListType):
instance_groups = [instance_groups]
params = {}
View
8 boto/mturk/connection.py
@@ -116,7 +116,7 @@ def _set_notification(self, hit_type, transport, destination, event_types=None):
Common SetHITTypeNotification operation to set notification for a
specified HIT type
"""
- assert type(hit_type) is str, "hit_type argument should be a string."
+ assert isinstance(hit_type, str), "hit_type argument should be a string."
params = {'HITTypeId': hit_type}
@@ -752,11 +752,11 @@ def get_keywords_as_string(keywords):
Returns a comma+space-separated string of keywords from either
a list or a string
"""
- if type(keywords) is list:
+ if isinstance(keywords, list):
keywords = ', '.join(keywords)
- if type(keywords) is str:
+ if isinstance(keywords, str):
final_keywords = keywords
- elif type(keywords) is unicode:
+ elif isinstance(keywords, unicode):
final_keywords = keywords.encode('utf-8')
elif keywords is None:
final_keywords = ""
View
2 boto/mturk/question.py
@@ -379,7 +379,7 @@ def get_as_xml(self):
if self.other:
# add OtherSelection element as xml if available
if hasattr(self.other, 'get_as_xml'):
- assert type(self.other) == FreeTextAnswer, 'OtherSelection can only be a FreeTextAnswer'
+ assert isinstance(self.other, FreeTextAnswer), 'OtherSelection can only be a FreeTextAnswer'
selections_xml += self.other.get_as_xml().replace('FreeTextAnswer', 'OtherSelection')
else:
selections_xml += "<OtherSelection />"
View
2 boto/mws/connection.py
@@ -162,7 +162,7 @@ def boolean_arguments(*fields):
def decorator(func):
def wrapper(*args, **kw):
- for field in filter(lambda x: type(kw.get(x)) is bool, fields):
+ for field in filter(lambda x: isinstance(kw.get(x), bool), fields):
kw[field] = str(kw[field]).lower()
return func(*args, **kw)
wrapper.__doc__ = "{}\nBooleans: {}".format(func.__doc__,
View
2 boto/s3/connection.py
@@ -193,7 +193,7 @@ def build_post_policy(self, expiration_time, conditions):
"""
Taken from the AWS book Python examples and modified for use with boto
"""
- assert type(expiration_time) == time.struct_time, \
+ assert isinstance(expiration_time, time.struct_time), \
'Policy document must include a valid expiration Time object'
# Convert conditions object mappings to condition statements
View
4 boto/sdb/db/manager/sdbmanager.py
@@ -581,7 +581,7 @@ def _build_filter_part(self, cls, filters, order_by=None, select=None):
for filter in filters:
filter_parts = []
filter_props = filter[0]
- if type(filter_props) != list:
+ if not isinstance(filter_props, list):
filter_props = [filter_props]
for filter_prop in filter_props:
(name, op) = filter_prop.strip().split(" ", 1)
@@ -672,7 +672,7 @@ def save_object(self, obj, expected_value=None):
if expected_value:
prop = obj.find_property(expected_value[0])
v = expected_value[1]
- if v is not None and not type(v) == bool:
+ if v is not None and not isinstance(v, bool):
v = self.encode_value(prop, v)
expected_value[1] = v
self.domain.put_attributes(obj.id, attrs, replace=True, expected_value=expected_value)
View
2 boto/sdb/db/property.py
@@ -540,7 +540,7 @@ def __get__(self, model_instance, model_class):
"""Fetches collection of model instances of this collection property."""
if model_instance is not None:
query = Query(self.__model)
- if type(self.__property) == list:
+ if isinstance(self.__property, list):
props = []
for prop in self.__property:
props.append("%s =" % prop)
View
2 boto/sdb/db/sequence.py
@@ -146,7 +146,7 @@ def __init__(self, id=None, domain_name=None, fnc=increment_by_one, init_val=Non
self.item_type = type(fnc(None))
self.timestamp = None
# Allow us to pass in a full name to a function
- if type(fnc) == str:
+ if isinstance(fnc, str):
from boto.utils import find_class
fnc = find_class(fnc)
self.fnc = fnc

0 comments on commit 601653c

Please sign in to comment.
Something went wrong with that request. Please try again.