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 hasattr() rather than isinstance(value, MutableSequence) #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

adamcharnock
Copy link

There are several places where the code checks specifically if something is an instance MutableSequence. I believe the more pythonic way would be something like:

# rather than this
if isinstance(value, collections.MutableSequence):
# do this:
if hasattr(value, '__iter__'):

From what I can see, iterability is what is actually desired, the other functionality of MutableSequence isn't needed.

For example, I have an object which is iterable and should therefore (AFAIK) be able to be decoded into a collection. However, right now it fails the check for being a MutableSequence.

This is potentially an extension of issue #18 from last year.

@adamcharnock adamcharnock changed the title Use hasattr() rather than isinstance(value, MutableSequence) Use hasattr() rather than isinstance(value, MutableSequence) Sep 20, 2015
@adamcharnock
Copy link
Author

Just updated to fix issues due to strings in python3 being iterable.

@jaimegildesagredo
Copy link
Owner

Hi @adamcharnock and thank you for the PR.

Just let me review if these changes have any other implication (specially the isinstance statements) before merging it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants