4747PyCF_ONLY_AST = 0x400
4848PyCF_ALLOW_INCOMPLETE_INPUT = 0x4000
4949
50- def _maybe_compile (compiler , source , filename , symbol ):
50+ def _maybe_compile (compiler , source , filename , symbol , flags ):
5151 # Check for source consisting of only blank lines and comments.
5252 for line in source .split ("\n " ):
5353 line = line .strip ()
@@ -61,22 +61,21 @@ def _maybe_compile(compiler, source, filename, symbol):
6161 with warnings .catch_warnings ():
6262 warnings .simplefilter ("ignore" , (SyntaxWarning , DeprecationWarning ))
6363 try :
64- compiler (source , filename , symbol )
64+ compiler (source , filename , symbol , flags = flags )
6565 except _IncompleteInputError :
6666 return None
6767 except SyntaxError : # Let other compile() errors propagate.
6868 pass
6969
7070 return compiler (source , filename , symbol , incomplete_input = False )
7171
72- def _compile (source , filename , symbol , incomplete_input = True ):
73- flags = 0
72+ def _compile (source , filename , symbol , incomplete_input = True , * , flags = 0 ):
7473 if incomplete_input :
7574 flags |= PyCF_ALLOW_INCOMPLETE_INPUT
7675 flags |= PyCF_DONT_IMPLY_DEDENT
7776 return compile (source , filename , symbol , flags )
7877
79- def compile_command (source , filename = "<input>" , symbol = "single" ):
78+ def compile_command (source , filename = "<input>" , symbol = "single" , flags = 0 ):
8079 r"""Compile a command and determine whether it is incomplete.
8180
8281 Arguments:
@@ -95,7 +94,7 @@ def compile_command(source, filename="<input>", symbol="single"):
9594 syntax error (OverflowError and ValueError can be produced by
9695 malformed literals).
9796 """
98- return _maybe_compile (_compile , source , filename , symbol )
97+ return _maybe_compile (_compile , source , filename , symbol , flags )
9998
10099class Compile :
101100 """Instances of this class behave much like the built-in compile
@@ -147,4 +146,4 @@ def __call__(self, source, filename="<input>", symbol="single"):
147146 syntax error (OverflowError and ValueError can be produced by
148147 malformed literals).
149148 """
150- return _maybe_compile (self .compiler , source , filename , symbol )
149+ return _maybe_compile (self .compiler , source , filename , symbol , flags = self . compiler . flags )
0 commit comments