gh-142595: add type check for namedtuple call during decimal initialization#142608
gh-142595: add type check for namedtuple call during decimal initialization#142608encukou merged 1 commit intopython:mainfrom
Conversation
|
Did you consider using a |
|
I'm not sure about issue itself, see #142595 (comment) But as an excuse for refactoring this sounds much better. I'll rework the pr. |
|
Hmm, no. I don't think using PyStructSequence is a good idea. We can't create this type just with PyStructSequence_NewType. The namedtype DecimalType supports three arguments, while new type - only one (a sequence). Probably, I can override tp_new, but at the end - things looks more complex with all this, not simpler. |
encukou
left a comment
There was a problem hiding this comment.
In general, it might be good to add a way to create PyStructSequences that are more namedtuple-like. But, yeah, I agree it's too much work for this issue.
|
Thanks @skirpichev for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
|
Thanks @skirpichev for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
…itialization (pythonGH-142608) (cherry picked from commit be5e0dc) Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
…itialization (pythonGH-142608) (cherry picked from commit be5e0dc) Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
|
GH-142622 is a backport of this pull request to the 3.13 branch. |
|
GH-142623 is a backport of this pull request to the 3.14 branch. |
I don't think that the amount of work is the problem: it seems, that interfaces are different. The namedtype has additional class method Perhaps, some PyStructSequence_NewType2(), that creates a type with the right constructor? If not, I think we should just document the difference. I was certainly misguided by sentence:
|
|
Yeah, that should reference the glossary term, not |
Yeah, this, with a new versioned variant of |
|
|
||
| obj = PyObject_CallMethod(collections, "namedtuple", "(ss)", "DecimalTuple", | ||
| "sign digits exponent"); | ||
| if (!PyType_Check(obj)) { |
There was a problem hiding this comment.
This will crash if obj is NULL. Use ASSIGN_PTR().
_decimal_execvia overridingcollections.namedtuple#142595