Skip to content

Commit

Permalink
Use isinstance for comparing types (E721) (#2087)
Browse files Browse the repository at this point in the history
Co-authored-by: Ramon Bartl <rb@ridingbytes.com>
  • Loading branch information
winniehell and ramonski authored Aug 1, 2022
1 parent 737e6a6 commit 09a552c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/senaite/core/browser/fields/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# Copyright 2018-2021 by it's authors.
# Some rights reserved, see README and LICENSE.

import six
from types import ClassType
from types import DictType
from types import ListType
from types import StringType
Expand Down Expand Up @@ -241,7 +243,7 @@ def set(self, instance, value, **kwargs):
ObjectField.set(self, instance, value, **kwargs)

def _to_dict(self, value):
if type(value) != type({}) and hasattr(value, 'keys'):
if not isinstance(value, dict) and hasattr(value, 'keys'):
new_value = {}
new_value.update(value)
return new_value
Expand All @@ -250,8 +252,8 @@ def _to_dict(self, value):
def _decode_strings(self, value, instance, **kwargs):
new_value = value
for k, v in value.items():
if type(v) is type(''):
nv = decode(v, instance, **kwargs)
if isinstance(v, six.string_types):
nv = decode(v, instance, **kwargs)
try:
new_value[k] = nv
except AttributeError: # Records don't provide __setitem__
Expand All @@ -277,7 +279,7 @@ def get(self, instance, **kwargs):
def _encode_strings(self, value, instance, **kwargs):
new_value = value
for k, v in value.items():
if type(v) is type(u''):
if isinstance(v, six.text_type):
nv = encode(v, instance, **kwargs)
try:
new_value[k] = nv
Expand Down
2 changes: 0 additions & 2 deletions travis_ci_flake8.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ extend-ignore =
E703,
# E713: test for membership should be 'not in'
E713,
# E721: do not compare types, use 'isinstance()'
E721,
# E722: do not use bare 'except'
E722,
# F403: 'from bika.lims.permissions import *' used; unable to detect undefined names
Expand Down

0 comments on commit 09a552c

Please sign in to comment.