Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linting issue E721: type-comparison #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions mediafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def _safe_cast(out_type, val):
if val is None:
return None

if out_type == int:
if out_type is int:
if isinstance(val, int) or isinstance(val, float):
# Just a number.
return int(val)
Expand All @@ -203,22 +203,22 @@ def _safe_cast(out_type, val):
match = re.match(r'[\+-]?[0-9]+', val.strip())
return int(match.group(0)) if match else 0

elif out_type == bool:
elif out_type is bool:
try:
# Should work for strings, bools, ints:
return bool(int(val))
except ValueError:
return False

elif out_type == str:
elif out_type is str:
if isinstance(val, bytes):
return val.decode('utf-8', 'ignore')
elif isinstance(val, str):
return val
else:
return str(val)

elif out_type == float:
elif out_type is float:
if isinstance(val, int) or isinstance(val, float):
return float(val)
else:
Expand Down Expand Up @@ -1271,13 +1271,13 @@ def _none_value(self):
"""Get an appropriate "null" value for this field's type. This
is used internally when setting the field to None.
"""
if self.out_type == int:
if self.out_type is int:
return 0
elif self.out_type == float:
elif self.out_type is float:
return 0.0
elif self.out_type == bool:
elif self.out_type is bool:
return False
elif self.out_type == str:
elif self.out_type is str:
return u''


Expand Down
Loading