diff --git a/genshi/compat.py b/genshi/compat.py index 2f8c481..2abca13 100644 --- a/genshi/compat.py +++ b/genshi/compat.py @@ -20,6 +20,7 @@ except ImportError: import _ast as ast import sys +import warnings from types import CodeType import six @@ -137,13 +138,15 @@ def build_code_chunk(code, filename, name, lineno): # In Python 3.8, Str and Ellipsis was replaced by Constant -try: - _ast_Ellipsis = ast.Ellipsis - _ast_Str = ast.Str - _ast_Str_value = lambda obj: obj.s -except AttributeError: - _ast_Ellipsis = _ast_Str = ast.Constant - _ast_Str_value = lambda obj: obj.value +with warnings.catch_warnings(): + warnings.filterwarnings('error', category=DeprecationWarning) + try: + _ast_Ellipsis = ast.Ellipsis + _ast_Str = ast.Str + _ast_Str_value = lambda obj: obj.s + except (AttributeError, DeprecationWarning): + _ast_Ellipsis = _ast_Str = ast.Constant + _ast_Str_value = lambda obj: obj.value class _DummyASTItem(object): pass