Skip to content

Poor error message when TypeError is raised during dict construction #116436

Closed

Description

@hauntsaninja
~/dev/cpython main λ cat z.py 
import random

def foo():
    yield random.randint(100)  # oops, only passed in one argument
    yield "value"

dict([foo() for _ in range(3)])

~/dev/cpython main λ python3.12 z.py                                                                   
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

I'd expect something like what PyPy gives:

Traceback (most recent call last):
  File "/Users/shantanu/dev/cpython/z.py", line 7, in <module>
    dict([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'

Linked PRs

Activity

  1. changed the title [-]Regression in error message when TypeError is raised during dict construction[/-] [+]Poor error message when TypeError is raised during dict construction[/+] on Mar 6, 2024
  2. added
    type-featureA feature request or enhancement
    and removed
    type-bugAn unexpected behavior, bug, or error
    on Mar 6, 2024
  3. added a commit that references this issue on Mar 6, 2024
  4. Rajendra1308 commented on Mar 7, 2024

    @Rajendra1308

    Hey @hauntsaninja I would like to work on this issue. Could you please provide more info and also what file needs to be modified?

  5. added a commit that references this issue on Apr 30, 2025
  6. StanFromIreland commented on Oct 13, 2025

    @StanFromIreland
    Member

    Triage: Can this be closed as completed?

  7. added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    pendingThe issue will be closed if no feedback is provided
    on Oct 13, 2025
  8. hauntsaninja commented on Oct 14, 2025

    @hauntsaninja
    ContributorAuthor

    Yup, this can be closed. I think I merged the PR after it went 18 months without a review

  9. removed
    pendingThe issue will be closed if no feedback is provided
    on Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions