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

Use isinstance for comparing types (E721) #2087

Merged
merged 2 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
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
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this import is unused and will make flake8 complain—I'll take care of this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in #2091

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to leave a comment on the next line (253/254) but GitHub won't let me. 🙄

Do we really want to return value here if it is not an instance of dict?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question and no idea at the moment. Anyways, these Archetype fields will be all removed as soon as we have migrated all contents/fields to Dexterity.

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