Title: Python 3.13.3 runs __iter__ twice in a list comprehension · Issue #132711 · python/cpython · GitHub
Open Graph Title: Python 3.13.3 runs __iter__ twice in a list comprehension · Issue #132711 · python/cpython
X Title: Python 3.13.3 runs __iter__ twice in a list comprehension · Issue #132711 · python/cpython
Description: Bug report Bug description: I can't upload comprehensionTestbed2.py because I am told the .py type is not allowed so I here is the script I used to reproduce this issue: =========================================== # TestClass: Class that...
Open Graph Description: Bug report Bug description: I can't upload comprehensionTestbed2.py because I am told the .py type is not allowed so I here is the script I used to reproduce this issue: ===========================...
X Description: Bug report Bug description: I can't upload comprehensionTestbed2.py because I am told the .py type is not allowed so I here is the script I used to reproduce this issue: =======================...
Opengraph URL: https://github.com/python/cpython/issues/132711
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Python 3.13.3 runs __iter__ twice in a list comprehension","articleBody":"# Bug report\n\n### Bug description:\n\nI can't upload comprehensionTestbed2.py because I am told the .py type is not allowed so I here is the script I used to reproduce this issue:\n\n===========================================\n\n```python\n# TestClass: Class that interacts with the DVD data file.\n\nclass TestClass:\n # Initialize the file timestamp.\n def __init__(self):\n pass\n # The iterator method.\n def __iter__(self):\n print('S1')\n self._index = 0\n return self\n # The next method.\n def __next__(self):\n print('S5')\n if self._index == 5:\n raise StopIteration\n value = self._index\n self._index += 1\n return value\n\n\n# Test code.\n\nprint('#1')\nfor n in TestClass():\n print(n)\n\nprint('#2')\nnumbers = [n for n in TestClass()]\nprint(numbers)\n```\n==============================================\n\nHere is the output of the Python script above:\n\n```\nD:\\Files\\Testing\u003e comprehensionTestbed2.py \n#1 \nS1 \nS5 \n0 \nS5 \n1 \nS5 \n2 \nS5 \n3 \nS5 \n4 \nS5 \n#2 \nS1 \nS1 \u003c----- The __iter__ method is invoked twice in the list comprehension when using 3.13.3 (and 3.13.2). \nS5 \nS5 \nS5 \nS5 \nS5 \nS5 \n[0, 1, 2, 3, 4] \n```\nThis does not happen with python 3.12.9 and is a real problem when the __iter__ method creates a mutex.\n\nEdward\n\n\n### CPython versions tested on:\n\n3.13\n\n### Operating systems tested on:\n\nWindows","author":{"url":"https://github.com/fb2078","@type":"Person","name":"fb2078"},"datePublished":"2025-04-18T22:24:33.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/132711/cpython/issues/132711"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8dd052e3-8fa7-5ed9-5d70-6e142b4406a1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C7B6:2C25B:93CC98:C472D6:6969BFCF |
| html-safe-nonce | 0fd1855ad59120fda92703b60874d51fcf27d56ee685219191096e9eabcb1556 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDN0I2OjJDMjVCOjkzQ0M5ODpDNDcyRDY6Njk2OUJGQ0YiLCJ2aXNpdG9yX2lkIjoiMTMxNjg1Nzk4OTk5NzExNzM5MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 57e92e8c1e97a0ce2762ee810dedfb3b42f5022d0437f07a30756caaa0bdd192 |
| hovercard-subject-tag | issue:3005859190 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/132711/issue_layout |
| twitter:image | https://opengraph.githubassets.com/53e58af489fe5e96967b1e5af30be2482fbb7c19e471936f235419443c5169b1/python/cpython/issues/132711 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/53e58af489fe5e96967b1e5af30be2482fbb7c19e471936f235419443c5169b1/python/cpython/issues/132711 |
| og:image:alt | Bug report Bug description: I can't upload comprehensionTestbed2.py because I am told the .py type is not allowed so I here is the script I used to reproduce this issue: ===========================... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | fb2078 |
| hostname | github.com |
| expected-hostname | github.com |
| None | acedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 83c08c21cdda978090dc44364b71aa5bc6dcea79 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width