8000 bpo-47152: Convert the re module into a package by serhiy-storchaka · Pull Request #32177 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-47152: Convert the re module into a package #32177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 2, 2022
Prev Previous commit
Next Next commit
Keep undescored names in the deprecated modules.
  • Loading branch information
serhiy-storchaka committed Apr 2, 2022
commit eedf86c38679f387af5fe588b941708804d2416d
3 changes: 2 additions & 1 deletion Lib/sre_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
DeprecationWarning,
stacklevel=2)

from re._compiler import *
from re import _compiler as _
globals().update({k: v for k, v in vars(_).items() if k[:2] != '__'})
3 changes: 2 additions & 1 deletion Lib/sre_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
DeprecationWarning,
stacklevel=2)

from re._constants import *
from re import _constants as _
globals().update({k: v for k, v in vars(_).items() if k[:2] != '__'})
3 changes: 2 additions & 1 deletion Lib/sre_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
DeprecationWarning,
stacklevel=2)

from re._parser import *
from re import _parser as _
globals().update({k: v for k, v in vars(_).items() if k[:2] != '__'})
17 changes: 16 additions & 1 deletion Lib/test/test_re.py
< 5212 tr data-hunk="2d1b03d8c267fda2ab5455852575ae6a2af28cda0151d23f06461703860eae95" class="show-top-border">
Original file line number Diff line number Diff line change
Expand Up @@ -2454,7 +2454,17 @@ def test_disallow_instantiation(self):
check_disallow_instantiation(self, type(pat.scanner("")))

def test_deprecated_modules(self):
for name in 'sre_compile', 'sre_constants', 'sre_parse':
deprecated = {
'sre_compile': ['compile', 'error',
'SRE_FLAG_IGNORECASE', 'SUBPATTERN',
'_compile_info'],
'sre_constants': ['error', 'SRE_FLAG_IGNORECASE', 'SUBPATTERN',
'_NamedIntConstant'],
'sre_parse': ['SubPattern', 'parse',
'SRE_FLAG_IGNORECASE', 'SUBPATTERN',
'_parse_sub'],
}
for name in deprecated:
with self.subTest(module=name):
sys.modules.pop(name, None)
with self.assertWarns(DeprecationWarning) as cm:
Expand All @@ -2463,6 +2473,11 @@ def test_deprecated_modules(self):
f"module {name!r} is deprecated")
self.assertEqual(cm.warnings[0].filename, __file__)
self.assertIn(name, sys.modules)
mod = sys.modules[name]
self.assertEqual(mod.__name__, name)
self.assertEqual(mod.__package__, '')
for attr in deprecated[name]:
self.assertTrue(hasattr(mod, attr))
del sys.modules[name]

class ExternalTests(unittest.TestCase):
Expand Down
0