Skip to content

Commit

Permalink
Do not use deprecated Ellipsis and Str
Browse files Browse the repository at this point in the history
  • Loading branch information
cedk committed Jun 8, 2024
1 parent e161256 commit c70de54
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions genshi/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
except ImportError:
import _ast as ast
import sys
import warnings
from types import CodeType

import six
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c70de54

Please sign in to comment.