Skip to content

Commit

Permalink
Merge pull request #73 from cedk/ast-warnings
Browse files Browse the repository at this point in the history
Silence deprecation warnings from attempting to import Ellipsis and Str (which are needed to support older Pythons).
  • Loading branch information
hodgestar authored Jun 11, 2024
2 parents e161256 + 26b6797 commit c6f4446
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
build_sdist:
name: Build sdist
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

Expand All @@ -37,7 +37,7 @@ jobs:

build_generic_wheel:
name: Build generic wheel (without speedups)
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
env:
# Build a wheel without speedups that can run on pure Python
GENSHI_BUILD_SPEEDUP: 0
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ on: [push, pull_request]

jobs:
tests:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [2.7, 3.6, 3.7, 3.8, 3.9, "3.10", "3.11-dev", pypy2, pypy3]
python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11", pypy2, pypy3]

steps:
- uses: actions/checkout@v2
Expand Down
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 c6f4446

Please sign in to comment.