Skip to content

Commit

Permalink
Replace type() comparisons with isinstance()
Browse files Browse the repository at this point in the history
  • Loading branch information
gholms committed Jun 8, 2012
1 parent 9539206 commit 601653c
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion boto/ec2/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)] = \
Expand Down
2 changes: 1 addition & 1 deletion boto/ec2/securitygroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions boto/emr/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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 = {}
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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 = {}
Expand Down
8 changes: 4 additions & 4 deletions boto/mturk/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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 = ""
Expand Down
2 changes: 1 addition & 1 deletion boto/mturk/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 />"
Expand Down
2 changes: 1 addition & 1 deletion boto/mws/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__,
Expand Down
2 changes: 1 addition & 1 deletion boto/s3/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions boto/sdb/db/manager/sdbmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion boto/sdb/db/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion boto/sdb/db/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 601653c

Please sign in to comment.