@@ -19,6 +19,7 @@ typedef struct {
1919 int optimize ;
2020 int ff_features ;
2121 int syntax_check_only ;
22+ int enable_warnings ;
2223
2324 _Py_c_array_t cf_finally ; /* context for PEP 765 check */
2425 int cf_finally_used ;
@@ -78,7 +79,7 @@ control_flow_in_finally_warning(const char *kw, stmt_ty n, _PyASTPreprocessState
7879static int
7980before_return (_PyASTPreprocessState * state , stmt_ty node_ )
8081{
81- if (state -> cf_finally_used > 0 ) {
82+ if (state -> enable_warnings && state -> cf_finally_used > 0 ) {
8283 ControlFlowInFinallyContext * ctx = get_cf_finally_top (state );
8384 if (ctx -> in_finally && ! ctx -> in_funcdef ) {
8485 if (!control_flow_in_finally_warning ("return" , node_ , state )) {
@@ -92,7 +93,7 @@ before_return(_PyASTPreprocessState *state, stmt_ty node_)
9293static int
9394before_loop_exit (_PyASTPreprocessState * state , stmt_ty node_ , const char * kw )
9495{
95- if (state -> cf_finally_used > 0 ) {
96+ if (state -> enable_warnings && state -> cf_finally_used > 0 ) {
9697 ControlFlowInFinallyContext * ctx = get_cf_finally_top (state );
9798 if (ctx -> in_finally && ! ctx -> in_loop ) {
9899 if (!control_flow_in_finally_warning (kw , node_ , state )) {
@@ -968,14 +969,15 @@ astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTPreprocessState *st
968969
969970int
970971_PyAST_Preprocess (mod_ty mod , PyArena * arena , PyObject * filename , int optimize ,
971- int ff_features , int syntax_check_only )
972+ int ff_features , int syntax_check_only , int enable_warnings )
972973{
973974 _PyASTPreprocessState state ;
974975 memset (& state , 0 , sizeof (_PyASTPreprocessState ));
975976 state .filename = filename ;
976977 state .optimize = optimize ;
977978 state .ff_features = ff_features ;
978979 state .syntax_check_only = syntax_check_only ;
980+ state .enable_warnings = enable_warnings ;
979981 if (_Py_CArray_Init (& state .cf_finally , sizeof (ControlFlowInFinallyContext ), 20 ) < 0 ) {
980982 return -1 ;
981983 }
0 commit comments