File tree 3 files changed +25
-0
lines changed 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ Change log for the astroid package (used to be astng)
4
4
--
5
5
* Enums created with functional syntax are now iterable
6
6
7
+ * Enums created with functional syntax are now subscriptable
8
+
7
9
* Don't crash when getting the string representation of BadUnaryOperationMessage
8
10
9
11
In some cases, when the operand does not have a .name attribute,
Original file line number Diff line number Diff line change @@ -200,6 +200,16 @@ class EnumAttribute(object):
200
200
return [EnumAttribute()]
201
201
def __next__(self):
202
202
return next(iter(self))
203
+ def __getitem__(self, attr):
204
+ class Value(object):
205
+ @property
206
+ def name(self):
207
+ return ''
208
+ @property
209
+ def value(self):
210
+ return attr
211
+
212
+ return Value()
203
213
''' )
204
214
class_node = infer_func_form (node , enum_meta ,
205
215
context = context , enum = True )[0 ]
Original file line number Diff line number Diff line change @@ -584,6 +584,19 @@ def test_enum_func_form_iterable(self):
584
584
self .assertIsInstance (inferred , astroid .Instance )
585
585
self .assertTrue (inferred .getattr ('__iter__' ))
586
586
587
+ def test_enum_func_form_subscriptable (self ):
588
+ instance , name = builder .extract_node ('''
589
+ from enum import Enum
590
+ Animal = Enum('Animal', 'ant bee cat dog')
591
+ Animal['ant'] #@
592
+ Animal['ant'].name #@
593
+ ''' )
594
+ instance = next (instance .infer ())
595
+ self .assertIsInstance (instance , astroid .Instance )
596
+
597
+ inferred = next (name .infer ())
598
+ self .assertIsInstance (inferred , astroid .Const )
599
+
587
600
588
601
@unittest .skipUnless (HAS_DATEUTIL , "This test requires the dateutil library." )
589
602
class DateutilBrainTest (unittest .TestCase ):
You can’t perform that action at this time.
0 commit comments