Title: Defining iterator in a separate class no longer works in 3.13 · Issue #128161 · python/cpython · GitHub
Open Graph Title: Defining iterator in a separate class no longer works in 3.13 · Issue #128161 · python/cpython
X Title: Defining iterator in a separate class no longer works in 3.13 · Issue #128161 · python/cpython
Description: Bug report Bug description: Defining an interator for a class in a separate class no longer works properly in 3.13. With the following test_iter.py: class list2(list): def __iter__(self): return list2iterator(self) class list2iterator: d...
Open Graph Description: Bug report Bug description: Defining an interator for a class in a separate class no longer works properly in 3.13. With the following test_iter.py: class list2(list): def __iter__(self): return li...
X Description: Bug report Bug description: Defining an interator for a class in a separate class no longer works properly in 3.13. With the following test_iter.py: class list2(list): def __iter__(self): return li...
Opengraph URL: https://github.com/python/cpython/issues/128161
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Defining iterator in a separate class no longer works in 3.13","articleBody":"# Bug report\n\n### Bug description:\n\nDefining an interator for a class in a separate class no longer works properly in 3.13. With the following `test_iter.py`:\n```python\nclass list2(list):\n def __iter__(self):\n return list2iterator(self)\n\nclass list2iterator:\n def __init__(self, X):\n self._X = X\n self._pointer = -1\n\n def __next__(self):\n self._pointer += 1\n if self._pointer == len(self._X):\n self._pointer = -1\n raise StopIteration\n return self._X[self._pointer]\n```\nWith Python 3.13.1 one gets:\n```python\n\u003e\u003e\u003e from test_iter import list2\n\u003e\u003e\u003e X=list2([1,2,3])\n\u003e\u003e\u003e [x for x in X]\nTraceback (most recent call last):\n File \"\u003cpython-input-2\u003e\", line 1, in \u003cmodule\u003e\n [x for x in X]\n ^\nTypeError: 'list2iterator' object is not iterable\n```\nWith Python 3.12.7 it works:\n```python\n\u003e\u003e\u003e from test_iter import list2\n\u003e\u003e\u003e X=list2([1,2,3])\n\u003e\u003e\u003e [x for x in X]\n[1, 2, 3]\n```\nBisected to https://github.com/python/cpython/commit/bcc7227e\n\n\n### CPython versions tested on:\n\n3.12, 3.13\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-134778\n* gh-134788\n* gh-134799\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/antonio-rojas","@type":"Person","name":"antonio-rojas"},"datePublished":"2024-12-21T19:47:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":22},"url":"https://github.com/128161/cpython/issues/128161"}
| 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:b17d1739-9fdf-582d-6dec-d7add56b252d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8DA6:D7362:3B7931:50404A:696AA908 |
| html-safe-nonce | 4dbdd7ad8a0bcf3a688bc29a1e162e01c363f3d71cfca4f10b343f9f9e895b1f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4REE2OkQ3MzYyOjNCNzkzMTo1MDQwNEE6Njk2QUE5MDgiLCJ2aXNpdG9yX2lkIjoiNDU3MDczMjQ2NzY0NjU0MDA0MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7cfbe07e2a6e7b50b7520cd2510fb9409ef7bb40cc8885bb5a4952ec65ec9d02 |
| hovercard-subject-tag | issue:2754335362 |
| 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/128161/issue_layout |
| twitter:image | https://opengraph.githubassets.com/78cacdb9906dbe6ce8e8c9f91b41dbff4e41ceb208e607356019ce3b495e36f1/python/cpython/issues/128161 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/78cacdb9906dbe6ce8e8c9f91b41dbff4e41ceb208e607356019ce3b495e36f1/python/cpython/issues/128161 |
| og:image:alt | Bug report Bug description: Defining an interator for a class in a separate class no longer works properly in 3.13. With the following test_iter.py: class list2(list): def __iter__(self): return li... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | antonio-rojas |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3eaf9b8cf1badcd7041a8ad480b9d9b28bea0ef1cc821ca9ff20f2cc7f4fe4b9 |
| 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 | dd9a979046e6382bd084e2bd873bf65f797125ff |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width