mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
[3.13] gh-125316: Fix using partial() as Enum member (GH-125361)
A FutureWarning with suggestion to use enum.member() is now emitted when the partial instance is used as an enum member.
This commit is contained in:
parent
d9dafc790d
commit
65e43ca6d9
3 changed files with 25 additions and 1 deletions
|
@ -11,6 +11,7 @@ import typing
|
|||
import builtins as bltns
|
||||
from collections import OrderedDict
|
||||
from datetime import date
|
||||
from functools import partial
|
||||
from enum import Enum, EnumMeta, IntEnum, StrEnum, EnumType, Flag, IntFlag, unique, auto
|
||||
from enum import STRICT, CONFORM, EJECT, KEEP, _simple_enum, _test_simple_enum
|
||||
from enum import verify, UNIQUE, CONTINUOUS, NAMED_FLAGS, ReprEnum
|
||||
|
@ -1537,6 +1538,19 @@ class TestSpecial(unittest.TestCase):
|
|||
[Outer.a, Outer.b, Outer.Inner],
|
||||
)
|
||||
|
||||
def test_partial(self):
|
||||
def func(a, b=5):
|
||||
return a, b
|
||||
with self.assertWarnsRegex(FutureWarning, r'partial.*enum\.member') as cm:
|
||||
class E(Enum):
|
||||
a = 1
|
||||
b = partial(func)
|
||||
self.assertEqual(cm.filename, __file__)
|
||||
self.assertIsInstance(E.b, partial)
|
||||
self.assertEqual(E.b(2), (2, 5))
|
||||
with self.assertWarnsRegex(FutureWarning, 'partial'):
|
||||
self.assertEqual(E.a.b(2), (2, 5))
|
||||
|
||||
def test_enum_with_value_name(self):
|
||||
class Huh(Enum):
|
||||
name = 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue