Mark Dickinson <dicki...@gmail.com> added the comment: Thanks for the patch, Daniel! It certainly fixes the problem. I was planning something a little more drastic, though---I think the struct module could do with a bit of a cleanup in this area.
At the moment it's not clear exactly what types should be accepted by struct.pack with an integer format. Just ints and longs (and their subclases)? Anything implementing an __index__ method? Anything implementing an __int__ method (e.g., Decimal instances)? I propose doing a little bit of rewriting so that (1) all attempted conversions of a PyObject to a C integer go through PyNumber_Index; thus anything with an __index__ method can be packed. (2) If PY_STRUCT_FLOAT_COERCE is defined, instances of float or subclasses of float (i.e., everything that passes PyFloat_Check) are also accepted, for backwards compatibility. Does this seem reasonable? ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue1741130> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com