Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-116436: Improve error message when TypeError occurs during dict update#116443

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
hauntsaninja merged 7 commits intopython:mainfromhauntsaninja:gh116436
Apr 30, 2025

Conversation

hauntsaninja
Copy link
Contributor

@hauntsaninjahauntsaninja commentedMar 6, 2024
edited
Loading

The example I gave in the issue now looks like:

Traceback (most recent call last):  File "/Users/shantanu/dev/cpython/z.py", line 8, in <module>    x.update([foo() for _ in range(3)])    ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/Users/shantanu/dev/cpython/z.py", line 4, in foo    yield random.randint(100)  # oops, only passed in one argument          ~~~~~~~~~~~~~~^^^^^TypeError: Random.randint() missing 1 required positional argument: 'b'Cannot convert dictionary update sequence element #0 to a sequence

Previously it was just:

Traceback (most recent call last):  File "/Users/shantanu/dev/cpython/z.py", line 7, in <module>    dict([foo() for _ in range(3)])TypeError: cannot convert dictionary update sequence element #0 to a sequence

@hauntsaninja
Copy link
ContributorAuthor

Hopefully this is a good use of exception notes, since it's just adding context. If not, maybe something withPyException_SetCause works

@@ -3515,13 +3515,14 @@ merge_from_seq2_lock_held(PyObject *d, PyObject *seq2, int override)
}

/* Convert item to sequence, and verify length 2. */
fast = PySequence_Fast(item, "");
fast = PySequence_Fast(item, "object is not iterable");
Copy link
ContributorAuthor

@hauntsaninjahauntsaninjaMar 6, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Technically, I guessPyObject_GetIter has a different error message for the edge case where__iter__ exists but returns a non-iterator.

I think nicest thing would be to changePySequence_Fast so that ifm is NULL it doesn't clobber the message

@sobolevnsobolevn changed the titlegh-116436: Improve error message when TypeError occurs during dict uupdategh-116436: Improve error message when TypeError occurs during dict updateMar 7, 2024
@python-cla-bot
Copy link

python-cla-botbot commentedApr 18, 2025
edited
Loading

All commit authors signed the Contributor License Agreement.

CLA signed

@hauntsaninjahauntsaninja merged commit7e8b153 intopython:mainApr 30, 2025
42 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@methanemethaneAwaiting requested review from methanemethane is a code owner

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

@pablogsalpablogsalAwaiting requested review from pablogsal

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@hauntsaninja

[8]ページ先頭

©2009-2025 Movatter.jp