From 7b7038d77b70b0db49f89697f0e51af0259cb5df Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 6 May 2022 15:30:17 +0000 Subject: [PATCH] chore: use isinstance() instead of type comparison --- googleapiclient/discovery.py | 12 +++--------- googleapiclient/model.py | 4 ++-- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/googleapiclient/discovery.py b/googleapiclient/discovery.py index c4d0eadb719..0188f1fe7a5 100644 --- a/googleapiclient/discovery.py +++ b/googleapiclient/discovery.py @@ -698,10 +698,7 @@ def _cast(value, schema_type): A string representation of 'value' based on the schema_type. """ if schema_type == "string": - if type(value) == type("") or type(value) == type(""): - return value - else: - return str(value) + return str(value) elif schema_type == "integer": return str(int(value)) elif schema_type == "number": @@ -709,10 +706,7 @@ def _cast(value, schema_type): elif schema_type == "boolean": return str(bool(value)).lower() else: - if type(value) == type("") or type(value) == type(""): - return value - else: - return str(value) + return str(value) def _media_size_to_long(maxSize): @@ -1075,7 +1069,7 @@ def method(self, **kwargs): for key, value in kwargs.items(): to_type = parameters.param_types.get(key, "string") # For repeated parameters we cast each member of the list. - if key in parameters.repeated_params and type(value) == type([]): + if key in parameters.repeated_params and isinstance(value, list): cast_value = [_cast(x, to_type) for x in value] else: cast_value = _cast(value, to_type) diff --git a/googleapiclient/model.py b/googleapiclient/model.py index 4ba27522357..02445f37a28 100644 --- a/googleapiclient/model.py +++ b/googleapiclient/model.py @@ -174,7 +174,7 @@ def _build_query(self, params): params.update({"alt": self.alt_param}) astuples = [] for key, value in params.items(): - if type(value) == type([]): + if isinstance(value, list): for x in value: x = x.encode("utf-8") astuples.append((key, x)) @@ -393,7 +393,7 @@ def makepatch(original, modified): # Use None to signal that the element is deleted patch[key] = None elif original_value != modified_value: - if type(original_value) == type({}): + if isinstance(original_value, dict): # Recursively descend objects patch[key] = makepatch(original_value, modified_value) else: