Skip to content

Commit d2a4f9b

Browse files
committed
Fix DeprecationWarning: module 'sre_parse' is deprecated
https://docs.python.org/3/whatsnew/3.11.html#modules Replace deprecated sre_parse with re._parser.
1 parent 30f8ca1 commit d2a4f9b

File tree

2 files changed

+45
-26
lines changed

2 files changed

+45
-26
lines changed

st2common/st2common/models/utils/action_alias_utils.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2020 The StackStorm Authors.
1+
# Copyright 2020-2026 The StackStorm Authors.
22
# Copyright 2019 Extreme Networks, Inc.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,17 +17,29 @@
1717

1818
import re
1919
import sys
20+
if sys.version_info >= (3, 11):
21+
from re._parser import ( # pylint: disable=E0611
22+
parse,
23+
AT,
24+
AT_BEGINNING,
25+
AT_BEGINNING_STRING,
26+
AT_END,
27+
AT_END_STRING,
28+
BRANCH,
29+
SUBPATTERN,
30+
)
31+
else:
32+
from sre_parse import ( # pylint: disable=E0611
33+
parse,
34+
AT,
35+
AT_BEGINNING,
36+
AT_BEGINNING_STRING,
37+
AT_END,
38+
AT_END_STRING,
39+
BRANCH,
40+
SUBPATTERN,
41+
)
2042

21-
from sre_parse import ( # pylint: disable=E0611
22-
parse,
23-
AT,
24-
AT_BEGINNING,
25-
AT_BEGINNING_STRING,
26-
AT_END,
27-
AT_END_STRING,
28-
BRANCH,
29-
SUBPATTERN,
30-
)
3143

3244
from st2common.util.jinja import render_values
3345
from st2common.constants import keyvalue as kv_constants
@@ -45,12 +57,7 @@
4557

4658
LOG = log.getLogger(__name__)
4759

48-
# Python 3 compatibility
49-
if sys.version_info > (3,):
50-
SUBPATTERN_INDEX = 3
51-
else:
52-
SUBPATTERN_INDEX = 1
53-
60+
SUBPATTERN_INDEX = 3
5461

5562
class ActionAliasFormatParser(object):
5663
def __init__(self, alias_format=None, param_stream=None):

st2common/tests/unit/test_action_alias_utils.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2020 The StackStorm Authors.
1+
# Copyright 2020-2026 The StackStorm Authors.
22
# Copyright 2019 Extreme Networks, Inc.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,14 +14,26 @@
1414
# limitations under the License.
1515

1616
from __future__ import absolute_import
17-
from sre_parse import (
18-
parse,
19-
AT,
20-
AT_BEGINNING,
21-
AT_BEGINNING_STRING,
22-
AT_END,
23-
AT_END_STRING,
24-
)
17+
18+
import sys
19+
if sys.version_info >= (3, 11):
20+
from re._parser import (
21+
parse,
22+
AT,
23+
AT_BEGINNING,
24+
AT_BEGINNING_STRING,
25+
AT_END,
26+
AT_END_STRING,
27+
)
28+
else:
29+
from sre_parse import (
30+
parse,
31+
AT,
32+
AT_BEGINNING,
33+
AT_BEGINNING_STRING,
34+
AT_END,
35+
AT_END_STRING,
36+
)
2537
from mock import Mock
2638
from unittest import TestCase
2739
from st2common.exceptions.content import ParseException

0 commit comments

Comments
 (0)