GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-126835: Remove unused docstring const by WolframAlph · Pull Request #130016 · python/cpython Conversation
|
| @support.cpython_only | |
| def test_remove_unused_consts(self): | |
| def f(): | |
| "docstring" | |
| if True: | |
| return "used" | |
| else: | |
| return "unused" | |
| self.assertEqual(f.__code__.co_consts, | |
| (f.__doc__, "used")) | |
| @support.cpython_only | |
| def test_remove_unused_consts_no_docstring(self): | |
| # the first item (None for no docstring in this case) is | |
| # always retained. | |
| def f(): | |
| if True: | |
| return "used" | |
| else: | |
| return "unused" | |
| self.assertEqual(f.__code__.co_consts, | |
| (True, "used")) |
True in co_consts but second one does even though it is not used (not used in first either) which is funny. Another example:
def f(): return x print(f.__code__.co_consts) # (None,)
None is in co_consts even though None is not used in f. It sneaks in by implicitly adding return None when compiling code unit, and it stays there because of always preserved slot for docstring.
Related comment: #126835 (comment)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
bec0789 to
3d34447
Compare
There was an error while loading. Please reload this page.
|
@iritkatriel let me know if you prefer having this linked to a separate issue. And also if we need to add some tests for this & news entry. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| index_map[i] = -1; | ||
| } | ||
| // The first constant may be docstring; keep it always. | ||
| index_map[0] = 0; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Maybe update the comment above? It's only kept when we have the docstring now
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR is stale because it has been open for 30 days with no activity. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.