Swallow warnings during anonymous compilation of source
This commit is contained in:
parent
8c475a45bb
commit
0d1f142b1c
|
@ -0,0 +1 @@
|
|||
Swallow warnings during anonymous compilation of source.
|
|
@ -8,6 +8,7 @@ import linecache
|
|||
import sys
|
||||
import textwrap
|
||||
import tokenize
|
||||
import warnings
|
||||
from ast import PyCF_ONLY_AST as _AST_FLAG
|
||||
from bisect import bisect_right
|
||||
|
||||
|
@ -288,6 +289,10 @@ def get_statement_startend2(lineno, node):
|
|||
def getstatementrange_ast(lineno, source, assertion=False, astnode=None):
|
||||
if astnode is None:
|
||||
content = str(source)
|
||||
# See #4260:
|
||||
# don't produce duplicate warnings when compiling source to find ast
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
astnode = compile(content, "source", "exec", _AST_FLAG)
|
||||
|
||||
start, end = get_statement_startend2(lineno, astnode)
|
||||
|
|
Loading…
Reference in New Issue