Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit88f6acf

Browse files
committed
add const string multiply test
1 parent1b1fcae commit88f6acf

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

‎Lib/test/test_compile.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,9 @@ def with_fstring():
906906
907907
def with_const_expression():
908908
"also" + " not docstring"
909+
910+
def multiple_const_strings():
911+
"not docstring " * 3
909912
""")
910913

911914
foroptin [0,1,2]:
@@ -922,6 +925,7 @@ def with_const_expression():
922925
self.assertIsNone(ns['two_strings'].__doc__)
923926
self.assertIsNone(ns['with_fstring'].__doc__)
924927
self.assertIsNone(ns['with_const_expression'].__doc__)
928+
self.assertIsNone(ns['multiple_const_strings'].__doc__)
925929

926930
@support.cpython_only
927931
deftest_docstring_interactive_mode(self):

‎Python/ast_opt.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,23 @@ static int astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTOptimize
676676
staticint
677677
astfold_body(asdl_stmt_seq*stmts,PyArena*ctx_,_PyASTOptimizeState*state)
678678
{
679+
intdocstring=_PyAST_GetDocString(stmts)!=NULL;
679680
CALL_SEQ(astfold_stmt,stmt,stmts);
681+
if (!docstring&&_PyAST_GetDocString(stmts)!=NULL) {
682+
stmt_tyst= (stmt_ty)asdl_seq_GET(stmts,0);
683+
asdl_expr_seq*values=_Py_asdl_expr_seq_new(1,ctx_);
684+
if (!values) {
685+
return0;
686+
}
687+
asdl_seq_SET(values,0,st->v.Expr.value);
688+
expr_tyexpr=_PyAST_JoinedStr(values,st->lineno,st->col_offset,
689+
st->end_lineno,st->end_col_offset,
690+
ctx_);
691+
if (!expr) {
692+
return0;
693+
}
694+
st->v.Expr.value=expr;
695+
}
680696
return1;
681697
}
682698

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp