6464
6565__all__ = ["compile_command" , "Compile" , "CommandCompiler" ]
6666
67- PyCF_DONT_IMPLY_DEDENT = 0x200 # Matches pythonrun.h
67+ PyCF_DONT_IMPLY_DEDENT = 0x200 # Matches pythonrun.h.
6868
6969def _maybe_compile (compiler , source , filename , symbol ):
70- # Check for source consisting of only blank lines and comments
70+ # Check for source consisting of only blank lines and comments.
7171 for line in source .split ("\n " ):
7272 line = line .strip ()
7373 if line and line [0 ] != '#' :
74- break # Leave it alone
74+ break # Leave it alone.
7575 else :
7676 if symbol != "eval" :
7777 source = "pass" # Replace it with a 'pass' statement
7878
79- err = err1 = err2 = None
80- code1 = code2 = None
81-
8279 try :
8380 return compiler (source , filename , symbol )
84- except SyntaxError :
81+ except SyntaxError : # Let other compile() errors propagate.
8582 pass
8683
8784 # Catch syntax warnings after the first compile
8885 # to emit warnings (SyntaxWarning, DeprecationWarning) at most once.
8986 with warnings .catch_warnings ():
9087 warnings .simplefilter ("error" )
9188
89+ code1 = err1 = err2 = None
9290 try :
9391 code1 = compiler (source + "\n " , filename , symbol )
9492 except SyntaxError as e :
@@ -102,6 +100,8 @@ def _maybe_compile(compiler, source, filename, symbol):
102100 try :
103101 if not code1 and _is_syntax_error (err1 , err2 ):
104102 raise err1
103+ else :
104+ return None
105105 finally :
106106 err1 = err2 = None
107107
0 commit comments