-
-
Notifications
You must be signed in to change notification settings - Fork 152
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
@@ -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__ | ||
|
@@ -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 | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in #2091