summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Lib/enum.py
diff options
context:
space:
mode:
authorshadchin <[email protected]>2022-04-18 12:39:32 +0300
committershadchin <[email protected]>2022-04-18 12:39:32 +0300
commitd4be68e361f4258cf0848fc70018dfe37a2acc24 (patch)
tree153e294cd97ac8b5d7a989612704a0c1f58e8ad4 /contrib/tools/python3/src/Lib/enum.py
parent260c02f5ccf242d9d9b8a873afaf6588c00237d6 (diff)
IGNIETFERRO-1816 Update Python 3 from 3.9.12 to 3.10.4
ref:9f96be6d02ee8044fdd6f124b799b270c20ce641
Diffstat (limited to 'contrib/tools/python3/src/Lib/enum.py')
-rw-r--r--contrib/tools/python3/src/Lib/enum.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/contrib/tools/python3/src/Lib/enum.py b/contrib/tools/python3/src/Lib/enum.py
index ee4c4c04f98..f5657a6eba2 100644
--- a/contrib/tools/python3/src/Lib/enum.py
+++ b/contrib/tools/python3/src/Lib/enum.py
@@ -44,10 +44,11 @@ def _is_sunder(name):
def _is_private(cls_name, name):
# do not use `re` as `re` imports `enum`
pattern = '_%s__' % (cls_name, )
+ pat_len = len(pattern)
if (
- len(name) >= 5
+ len(name) > pat_len
and name.startswith(pattern)
- and name[len(pattern)] != '_'
+ and name[pat_len:pat_len+1] != ['_']
and (name[-1] != '_' or name[-2] != '_')
):
return True
@@ -97,7 +98,7 @@ class _EnumDict(dict):
if _is_private(self._cls_name, key):
import warnings
warnings.warn(
- "private variables, such as %r, will be normal attributes in 3.10"
+ "private variables, such as %r, will be normal attributes in 3.11"
% (key, ),
DeprecationWarning,
stacklevel=2,
@@ -392,12 +393,19 @@ class EnumMeta(type):
start=start,
)
- def __contains__(cls, member):
- if not isinstance(member, Enum):
+ def __contains__(cls, obj):
+ if not isinstance(obj, Enum):
+ import warnings
+ warnings.warn(
+ "in 3.12 __contains__ will no longer raise TypeError, but will return True if\n"
+ "obj is a member or a member's value",
+ DeprecationWarning,
+ stacklevel=2,
+ )
raise TypeError(
"unsupported operand type(s) for 'in': '%s' and '%s'" % (
- type(member).__qualname__, cls.__class__.__qualname__))
- return isinstance(member, cls) and member._name_ in cls._member_map_
+ type(obj).__qualname__, cls.__class__.__qualname__))
+ return isinstance(obj, cls) and obj._name_ in cls._member_map_
def __delattr__(cls, attr):
# nicer error message when someone tries to delete an attribute
@@ -705,7 +713,8 @@ class Enum(metaclass=EnumMeta):
'error in %s._missing_: returned %r instead of None or a valid member'
% (cls.__name__, result)
)
- exc.__context__ = ve_exc
+ if not isinstance(exc, ValueError):
+ exc.__context__ = ve_exc
raise exc
finally:
# ensure all variables that could hold an exception are destroyed