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

Checking int the "convert_list" function. #9

Closed
akryazhev opened this issue Jul 11, 2013 · 3 comments
Closed

Checking int the "convert_list" function. #9

akryazhev opened this issue Jul 11, 2013 · 3 comments

Comments

@akryazhev
Copy link

elif type(item) in (list, set, tuple):
May be this checking is too narrow? It will be cool to make it more wide.
For example, let it to use any iterable Python-object.

@quandyfactory
Copy link
Owner

Looking into this, it seems I may be better off using the isinstance() function rather than the type() function. The advantage is that isinstance() recognizes the base class of derived classes, such that:

from collections import OrderedDict
test = OrderedDict({ 'foo': 'bar' })
type(test) == dict
False
isinstance(test, dict)
True

So if I test for isinstance(item, dict) the function will work for dict-like objects as well as pure dicts.

@akryazhev
Copy link
Author

Yes, I think this variant is better the previous too. I think it is make sense to wide this checking too:

type(v) in (list, set, tuple)
for example:
import collections
isinstance(v, collections.Iterable):

@quandyfactory
Copy link
Owner

Fixed in version 1.3. Thanks again for recommending a good change to the library.

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

No branches or pull requests

2 participants