Skip to content

Commit d7ff429

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 d7ff429

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

st2common/st2common/models/utils/action_alias_utils.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,24 @@
1717

1818
import re
1919
import sys
20-
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-
)
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+
)
29+
else:
30+
from sre_parse import ( # pylint: disable=E0611
31+
parse,
32+
AT,
33+
AT_BEGINNING,
34+
AT_BEGINNING_STRING,
35+
AT_END,
36+
AT_END_STRING,
37+
)
3138

3239
from st2common.util.jinja import render_values
3340
from st2common.constants import keyvalue as kv_constants

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)