Importing the enum module in the re module slows down Python startup by 34% when Python is run from a virtual environment, or more generally when the re module is imported at startup but not the enum module.
This commit is contained in:
parent
9b88fdf4f0
commit
1ec1cd161b
33
Lib/re.py
33
Lib/re.py
|
@ -119,7 +119,6 @@ This module also defines an exception 'error'.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import enum
|
|
||||||
import sre_compile
|
import sre_compile
|
||||||
import sre_parse
|
import sre_parse
|
||||||
import functools
|
import functools
|
||||||
|
@ -139,26 +138,18 @@ __all__ = [
|
||||||
|
|
||||||
__version__ = "2.2.1"
|
__version__ = "2.2.1"
|
||||||
|
|
||||||
class RegexFlag(enum.IntFlag):
|
# flags
|
||||||
ASCII = sre_compile.SRE_FLAG_ASCII # assume ascii "locale"
|
A = ASCII = sre_compile.SRE_FLAG_ASCII # assume ascii "locale"
|
||||||
IGNORECASE = sre_compile.SRE_FLAG_IGNORECASE # ignore case
|
I = IGNORECASE = sre_compile.SRE_FLAG_IGNORECASE # ignore case
|
||||||
LOCALE = sre_compile.SRE_FLAG_LOCALE # assume current 8-bit locale
|
L = LOCALE = sre_compile.SRE_FLAG_LOCALE # assume current 8-bit locale
|
||||||
UNICODE = sre_compile.SRE_FLAG_UNICODE # assume unicode "locale"
|
U = UNICODE = sre_compile.SRE_FLAG_UNICODE # assume unicode "locale"
|
||||||
MULTILINE = sre_compile.SRE_FLAG_MULTILINE # make anchors look for newline
|
M = MULTILINE = sre_compile.SRE_FLAG_MULTILINE # make anchors look for newline
|
||||||
DOTALL = sre_compile.SRE_FLAG_DOTALL # make dot match newline
|
S = DOTALL = sre_compile.SRE_FLAG_DOTALL # make dot match newline
|
||||||
VERBOSE = sre_compile.SRE_FLAG_VERBOSE # ignore whitespace and comments
|
X = VERBOSE = sre_compile.SRE_FLAG_VERBOSE # ignore whitespace and comments
|
||||||
A = ASCII
|
|
||||||
I = IGNORECASE
|
# sre extensions (experimental, don't rely on these)
|
||||||
L = LOCALE
|
T = TEMPLATE = sre_compile.SRE_FLAG_TEMPLATE # disable backtracking
|
||||||
U = UNICODE
|
DEBUG = sre_compile.SRE_FLAG_DEBUG # dump pattern after compilation
|
||||||
M = MULTILINE
|
|
||||||
S = DOTALL
|
|
||||||
X = VERBOSE
|
|
||||||
# sre extensions (experimental, don't rely on these)
|
|
||||||
TEMPLATE = sre_compile.SRE_FLAG_TEMPLATE # disable backtracking
|
|
||||||
T = TEMPLATE
|
|
||||||
DEBUG = sre_compile.SRE_FLAG_DEBUG # dump pattern after compilation
|
|
||||||
globals().update(RegexFlag.__members__)
|
|
||||||
|
|
||||||
# sre exception
|
# sre exception
|
||||||
error = sre_compile.error
|
error = sre_compile.error
|
||||||
|
|
Loading…
Reference in New Issue