-
Notifications
You must be signed in to change notification settings - Fork 336
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
Remove isinstance() check for namedtuple_as_object #22
Conversation
Using isinstance() is not Pythonic and should be avoided when possible. By using duck-typing instead, we can easily support other objects that do not inherit from tuple but still support the same API as namedtuple, such as objects created using the `recordtype` library: http://pypi.python.org/pypi/recordtype
This seems like a reasonable thing to do, but I will need some tests and updates to docs (index.rst) to reflect the change. Do you want to do this? If not, I'll get around to it in the next few weeks. |
Take a look at this branch, includes your changes and I added some docs and tests. Had a bit more time than I expected today. master...namedtuple_duck-gh22 |
Looks good to me! Sorry it took me so long to get back to this. Do you need me to do anything to get this merged into master? |
Version 2.5.2 released 2012-05-10 * Fix for regression introduced in 2.5.1 simplejson/simplejson#35 Version 2.5.1 released 2012-05-10 * Support for use_decimal=True in environments that use Python sub-interpreters such as uWSGI simplejson/simplejson#34 Version 2.5.0 released 2012-03-29 * New item_sort_key option for encoder to allow fine grained control of sorted output Version 2.4.0 released 2012-03-06 * New bigint_as_string option for encoder to trade JavaScript number precision issues for type issues. simplejson/simplejson#31 Version 2.3.3 released 2012-02-27 * Allow unknown numerical types for indent parameter simplejson/simplejson#29 Version 2.3.2 released 2011-12-30 * Fix crashing regression in speedups introduced in 2.3.1 Version 2.3.1 released 2011-12-29 * namedtuple_as_object now checks _asdict to ensure that it is callable. simplejson/simplejson#26 Version 2.3.0 released 2011-12-05 * Any objects with _asdict() methods are now considered for namedtuple_as_object. simplejson/simplejson#22
Version 2.5.2 released 2012-05-10 * Fix for regression introduced in 2.5.1 simplejson/simplejson#35 Version 2.5.1 released 2012-05-10 * Support for use_decimal=True in environments that use Python sub-interpreters such as uWSGI simplejson/simplejson#34 Version 2.5.0 released 2012-03-29 * New item_sort_key option for encoder to allow fine grained control of sorted output Version 2.4.0 released 2012-03-06 * New bigint_as_string option for encoder to trade JavaScript number precision issues for type issues. simplejson/simplejson#31 Version 2.3.3 released 2012-02-27 * Allow unknown numerical types for indent parameter simplejson/simplejson#29 Version 2.3.2 released 2011-12-30 * Fix crashing regression in speedups introduced in 2.3.1 Version 2.3.1 released 2011-12-29 * namedtuple_as_object now checks _asdict to ensure that it is callable. simplejson/simplejson#26 Version 2.3.0 released 2011-12-05 * Any objects with _asdict() methods are now considered for namedtuple_as_object. simplejson/simplejson#22
Using isinstance() is not Pythonic and should be avoided when possible.
By using duck-typing instead, we can easily support other objects
that do not inherit from tuple but still support the same API as
namedtuple, such as objects created using the
recordtype
library:http://pypi.python.org/pypi/recordtype