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
Decimal constants should be the same for py & c module versions #60626
Comments
Right now decimal.py defines 'ROUND_DOWN' as 'ROUND_DOWN' (string), whereas C version define it as 1 (integer). While using constant values directly in your code is not a good idea, there is another case where it doesn't work: if you serialize decimal values along with their meta information, such as rounding settings. In this case, when you unserialize data that was serialized with python decimal, those meta-settings won't work for 'c' decimal. |
I think it's already true that pickling a Decimal context on Python 3.2 and unpickling on Python 3.3 doesn't work. Stefan: do I recall that this is a known issue? |
Pickling changed in 3.3 to make the C and Python versions compatible. So pickled Pickling a list of rounding modes is not compatible. |
Well, I don't care about py 3.2 & 3.3 pickle compatibility in this particular issue. This one is about compatibility of py & c decimal modules in 3.3. |
So what data structure are you trying to serialize interchangeably? |
I see that you mentioned the use case in your first mail. Yes, that isn't |
Right ;) Is there any chance we can fix that in next 3.3 point release or 3.4? |
It would be possible to translate strings to integers; the infrastructure See Modules/_decimal/_decimal.c:1211 for the code that would need to context.rounding = ROUND_UP |
Well, I suppose one could use a cascaded switch statement, starting with the "ROUND_CEILING" That should be as fast as PyLong_AsLong(). |
In the absence of an enum type, string constants are nicer to read in |
New changeset 733bb4fd9888 by Stefan Krah in branch '3.3': |
In the version I committed the string constants are interned, so |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: