mirror of
https://github.com/python/cpython.git
synced 2025-07-19 17:25:54 +00:00
bpo-40066: Enum: modify repr()
and str()
(GH-22392)
* Enum: streamline repr() and str(); improve docs - repr() is now ``enum_class.member_name`` - stdlib global enums are ``module_name.member_name`` - str() is now ``member_name`` - add HOW-TO section for ``Enum`` - change main documentation to be an API reference
This commit is contained in:
parent
51a85ddce8
commit
b775106d94
19 changed files with 2225 additions and 1491 deletions
17
Lib/re.py
17
Lib/re.py
|
@ -142,6 +142,7 @@ __all__ = [
|
|||
|
||||
__version__ = "2.2.1"
|
||||
|
||||
@enum.global_enum
|
||||
class RegexFlag(enum.IntFlag, boundary=enum.KEEP):
|
||||
ASCII = A = sre_compile.SRE_FLAG_ASCII # assume ascii "locale"
|
||||
IGNORECASE = I = sre_compile.SRE_FLAG_IGNORECASE # ignore case
|
||||
|
@ -154,22 +155,6 @@ class RegexFlag(enum.IntFlag, boundary=enum.KEEP):
|
|||
TEMPLATE = T = sre_compile.SRE_FLAG_TEMPLATE # disable backtracking
|
||||
DEBUG = sre_compile.SRE_FLAG_DEBUG # dump pattern after compilation
|
||||
|
||||
def __repr__(self):
|
||||
res = ''
|
||||
if self._name_:
|
||||
member_names = self._name_.split('|')
|
||||
constant = None
|
||||
if member_names[-1].startswith('0x'):
|
||||
constant = member_names.pop()
|
||||
res = 're.' + '|re.'.join(member_names)
|
||||
if constant:
|
||||
res += '|%s' % constant
|
||||
return res
|
||||
|
||||
__str__ = object.__str__
|
||||
|
||||
globals().update(RegexFlag.__members__)
|
||||
|
||||
# sre exception
|
||||
error = sre_compile.error
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue