Skip to content

Commit

Permalink
pydrive2: use isinstance() instead of type() (#291)
Browse files Browse the repository at this point in the history
Looks like this was an anti pattern that stuck around from some early
days.

Fixes iterative/dvc-gdrive#31
  • Loading branch information
efiop authored Jul 5, 2023
1 parent 53ee84c commit 30c0f48
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pydrive2/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def GetContentString(
"""
if (
self.content is None
or type(self.content) is not io.BytesIO
or not isinstance(self.content, io.BytesIO)
or self.has_bom == remove_bom
):
self.FetchContent(mimetype, remove_bom)
Expand Down
4 changes: 2 additions & 2 deletions pydrive2/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ def _ValidateSettingsElement(data, struct, key):
else:
data[key] = default
# If data exists, Check type of the data
elif type(value) is not data_type:
elif not isinstance(value, data_type):
raise InvalidConfigError(f"Setting {key} should be type {data_type}")
# If type of this data is dict, check if structure of the data is valid.
if data_type is dict:
_ValidateSettingsStruct(data[key], struct[key]["struct"])
# If type of this data is list, check if all values in the list is valid.
elif data_type is list:
for element in data[key]:
if type(element) is not struct[key]["struct"]:
if not isinstance(element, struct[key]["struct"]):
raise InvalidConfigError(
"Setting %s should be list of %s"
% (key, struct[key]["struct"])
Expand Down

0 comments on commit 30c0f48

Please sign in to comment.