summaryrefslogtreecommitdiff
path: root/Lib/codeop.py
diff options
context:
space:
mode:
authorCheryl Sabella <cheryl.sabella@gmail.com>2020-06-04 19:40:24 -0400
committerGitHub <noreply@github.com>2020-06-04 19:40:24 -0400
commit052d3fc0907be253cfd64b2c737a0b0aca586011 (patch)
tree3d50f8cb5dbbdab51518e443c456b24f7172aa0d /Lib/codeop.py
parent3744ed2c9c0b3905947602fc375de49533790cb9 (diff)
downloadcpython-git-052d3fc0907be253cfd64b2c737a0b0aca586011.tar.gz
bpo-40807: Show warnings once from codeop._maybe_compile (#20486)
* bpo-40807: Show warnings once from codeop._maybe_compile * Move catch_warnings * news Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Diffstat (limited to 'Lib/codeop.py')
-rw-r--r--Lib/codeop.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/Lib/codeop.py b/Lib/codeop.py
index 835e68c09b..7e192ea6a1 100644
--- a/Lib/codeop.py
+++ b/Lib/codeop.py
@@ -57,6 +57,7 @@ Compile():
"""
import __future__
+import warnings
_features = [getattr(__future__, fname)
for fname in __future__.all_feature_names]
@@ -83,15 +84,18 @@ def _maybe_compile(compiler, source, filename, symbol):
except SyntaxError:
pass
- try:
- code1 = compiler(source + "\n", filename, symbol)
- except SyntaxError as e:
- err1 = e
-
- try:
- code2 = compiler(source + "\n\n", filename, symbol)
- except SyntaxError as e:
- err2 = e
+ # Suppress warnings after the first compile to avoid duplication.
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore")
+ try:
+ code1 = compiler(source + "\n", filename, symbol)
+ except SyntaxError as e:
+ err1 = e
+
+ try:
+ code2 = compiler(source + "\n\n", filename, symbol)
+ except SyntaxError as e:
+ err2 = e
try:
if code: