gh-96052: codeop: fix handling compiler warnings in incomplete input … · python/cpython@426d72e

GitHub

Original file line numberDiff line numberDiff line change@@ -56,22 +56,22 @@ def _maybe_compile(compiler, source, filename, symbol):

5656ifsymbol!="eval":

5757source="pass"# Replace it with a 'pass' statement

585859-try:

60-returncompiler(source, filename, symbol)

61-exceptSyntaxError: # Let other compile() errors propagate.

62-pass

63-64-# Catch syntax warnings after the first compile

65-# to emit warnings (SyntaxWarning, DeprecationWarning) at most once.

59+# Disable compiler warnings when checking for incomplete input.

6660withwarnings.catch_warnings():

67-warnings.simplefilter("error")

68-61+warnings.simplefilter("ignore", (SyntaxWarning, DeprecationWarning))

6962try:

70-compiler(source+"\n", filename, symbol)

71-exceptSyntaxErrorase:

72-if"incomplete input"instr(e):

63+compiler(source, filename, symbol)

64+exceptSyntaxError: # Let other compile() errors propagate.

65+try:

66+compiler(source+"\n", filename, symbol)

7367returnNone

74-raise

68+exceptSyntaxErrorase:

69+if"incomplete input"instr(e):

70+returnNone

71+# fallthrough

72+73+returncompiler(source, filename, symbol)

74+75757676def_is_syntax_error(err1, err2):

7777rep1=repr(err1)