-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
gh-102431: clarify constraints on arguments of logical_xxx methods #102836
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
Conversation
BTW, maybe it does make sense to add |
I would go farther an include the full text and examples used in
Anything less that this will just leave the user guessing about how to use these weird functions. |
Agreed. But there should be some formal description too, because "The operands must be both logical numbers." sounds cryptic even after examples... Or do you think it's ok? (The notion of "logical number" is well defined in the sphinx docs.) I'll sync docstrings for C/Python implementations and add examples. |
Ok, now docstrings of Context's methods are in sync.
Basically, this shows everything: constraints on digits of operands, how it works digits-wise and how it works with coefficients of different length. I think it should reduce misunderstanding to minimum. |
@rhettinger, does it make sense for you now? |
CC @picnixz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense to have the inline definition of what a logical operand is but OTOH, one could say that the online docs should be sufficient so I'm neutral on this.
Sorry, I am not a Decimal expert and do not know why such weird operations exist at first place (perhaps it is just the part of some standard). From practical point of view, I would just refer "logical integers" in the docstrings, and defined them in the module documentation. If you want to add examples in the docstrings and if there are examples in other docstring, I think that a single example per method should be enough. With multiple digits you can cover all cases by a single example. The rest can be added in the module documentation. |
@serhiy-storchaka, sure. If you see something odd in the decimal module - IMO, it's coming from the IBM standard. JFR: https://speleotrove.com/decimal/damisc.html
Current patch just sync Python (which has extensive examples for context functions) and C implementation. Do you think that we should remove (most) examples from pure-Python version? |
Well, then we should keep examples. They are not just the documentation, but doctests. But new additions are incorrect. "Both operands should have zero sign and exponent, and digits either 0 or 1." Operands can be integers, and integers don't have exponent or digits. Lets leave a more detailed explanation to the module documentation. |
I doubt we should be more verbose here (docstrings!). And I don't think that sphinx docs needs to be expanded. Context docs already assume that integers are coerced to Decimal's: "Each Context method accepts a Python integer (an instance of int) anywhere that a Decimal instance is accepted." |
I also do not think that we should be more verbose here. |
CC @vstinner |
PR updated after recent transition of the C decimal module to AC, please review. Python and C docstrings are in sync. Tiny difference is indentation of examples for C version (for consistency with other docstrings). Former Python docstrings (not all) have remarks like "The operands must be both logical numbers." We can use that instead of verbose "Both operands should have zero sign and exponent, and digits either 0 or 1." Notion of "logical number" is explained in sphinx docs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Yes, please keep old remarks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I'm fine with "The operands must be both logical numbers."
@serhiy-storchaka, done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 👍
Thanks @skirpichev for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
Sorry, @skirpichev and @serhiy-storchaka, I could not cleanly backport this to
|
Sorry, @skirpichev and @serhiy-storchaka, I could not cleanly backport this to
|
I'll provide backports. |
…gical operations (pythonGH-102836) Sync C/Python implementation of the decimal: logical_ops for contexts. (cherry picked from commit 6ecf77d) Co-authored-by: Sergey B Kirpichev <[email protected]>
GH-140105 is a backport of this pull request to the 3.14 branch. |
…gical operations (pythonGH-102836) Sync C/Python implementation of the decimal: logical_ops for contexts. (cherry picked from commit 6ecf77d) Co-authored-by: Sergey B Kirpichev <[email protected]>
GH-140106 is a backport of this pull request to the 3.13 branch. |
Uh oh!
There was an error while loading. Please reload this page.