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-126072: Set docstring attribute for module and class by xuantengh · Pull Request #126231 · python/cpython Conversation
|
|
Just kindly to ask any further updates needed? I'm not sure whether it's proper to re-request review in CPython PR workflow. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Excuse formatting, reviewing on my phone.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| PyObject *docstring = _PyAST_GetDocString(body); | ||
| assert(OPTIMIZATION_LEVEL(c) < 2 || docstring == NULL); | ||
| if (docstring) { | ||
| assert(ste->ste_has_docstring); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is it still true that GetDocstring returns non-null only when ste_has_docstring is true?
Perhaps it should be
if(ste_has_docstring) assert(GetDocstring)?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Currently I think they are equivalent, i.e., ste_has_docstring == 1 iff. there is a docstring during symbol table generation.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
And when you run python -OO?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Currently when running with -OO, the first docstring is removed and the subsequent docstring is converted into JoinedStr in the AST stage. For _PyAST_GetDocString, it will not identify the converted JoinedStr as docstring, so ste_has_docstring will not be set.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Add a test for docstring optimization under -OO.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Currently when running with
-OO, the first docstring is removed and the subsequent docstring is converted intoJoinedStrin the AST stage. For_PyAST_GetDocString, it will not identify the convertedJoinedStras docstring, soste_has_docstringwill not be set.
Right, but we want to remove that hack.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Should we do it in this PR?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
d9c97a6 to
7db42a1
Compare
|
@iritkatriel Hi, I've encountered an issue when trying to remove f-string conversion in def func(): "not " + "a docstring"
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I thought the idea is that it uses |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry I'm a little confused now. 😂 If we remove the f-string conversion in the Lines 1846 to 1848 in 83ba8c2
The reason is If there is something I misunderstood, please correct me, thanks! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I guess the problem is that we perform AST optimization before we build the symtable, so we have to keep doing the f-string conversion to avoid breaking the symtable. Maybe we can instead run the symtable before ast optimization, so we can get rid of the f-string trick in the AST optimizer. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Yeah that's the problem. That's say, we cannot convey the information from AST construction to symtable generation phase.
Theoratically it's feasible, but I'm afraid that there are side-effects and the scope is beyond this PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
My proposal (in #126072 (comment)) was to move the docstring removal to the symtable, so it's all in one place. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
But I think the problem is still not addressed, we've lost some information after the AST optimization (the concatenated string has been optimized as constant string). Even though the docstring removal is put together with symtable, it still fails to distinguish in the above case. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
75bfe7b to
0f06e57
Compare
2194f4f to
390caaa
Compare
|
Revert to the version without swapping AST optimization and symtable generation. The docstring removal in |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
No, this would mean we optimise less when we should be optimising more. I think we should leave symtable after ast_opt and try my suggestion to just move the docstring handling from ast_opt to symtable. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
As mentioned above, what blocks us doing so is if we leave the docstring handling to symtable, for the following code: def with_const_expression(): "aa" * 4 The optimized AST will be: Module( body=[ FunctionDef( name='with_const_expression', args=arguments(), body=[ Expr( value=Constant(value='aaaaaaaa'))])]) Then in the symtable stage, it cannot distinguish whether the constant string |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ok, I see. I think we should just forget about that for this PR. Can you revert all the changes related to removing the hack, and make this PR just about about module and class change? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
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.