-
-
Notifications
You must be signed in to change notification settings - Fork 32.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
base: main
Are you sure you want to change the base?
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 |
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 suggest to remove "both have zero sign and exponent, and digits either 0 or 1" from the docstrings. It is not accurate.
@serhiy-storchaka, why do you think so? If you are about "Operands can be integers, and integers don't have exponent or digits." - no, they can't. Context's docs says, that integers are coerced to Decimal's. So, I think we can assume, that both operands are Decimal's. |
|
But for Even if this is not incorrect for |
No. But you are right, it's not documented how handled integer arguments for Decimal's methods. Perhaps, we should add analog of "Each Context method accepts a Python integer (an instance of int) anywhere that a Decimal instance is accepted." to the Decimal class docs.
I doubt they are accurate. For example, Maybe we should just sync docstrings of pure-Python and C-codec versions, ensure they have same set of examples and each mention, that operands are "logical" arguments (without - yes - a repetitive definitions)? |
Uh oh!
There was an error while loading. Please reload this page.