Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#31057 closed Bug (invalid)

Choices enum - Inconsistent values.

Reported by: laevilgenius Owned by: nobody
Component: Database layer (models, ORM) Version: 3.0
Severity: Normal Keywords: enum
Cc: Shai Berger, pope1ni Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Labeled enum members have their values wrapped in tuples:

class E(Choices):
    FOO = 1
    BAR = 2, 'bar'

>>> E.FOO.value
1
>>> E.BAR.value
(2,)

Change History (2)

comment:1 by Mariusz Felisiak, 7 years ago

Cc: Shai Berger pope1ni added
Resolution: → invalid
Status: new → closed
Summary: Choices enum - Inconsistent values → Choices enum - Inconsistent values.

Choices are supported if you need a concrete data type other than int or str. In such cases you should subclass Choices and the required concrete data type (see ​documentation and ​examples), so described usage is not supported. In your case you can use IntegerChoices.

comment:2 by laevilgenius, 7 years ago

Could we rise an exception in such case then?
Add something like this to metaclass for example:

if classdict._member_names and cls._member_type_ is object:
    raise TypeError(...)
Version 0, edited 7 years ago by laevilgenius (next)
Note: See TracTickets for help on using tickets.
Back to Top