django-extended-choices
django-extended-choices copied to clipboard
If constant starts with numeral, CHOICE.<CONSTANT> fails
If the constant starts with a numeral (potentially other non-alpha too), the CHOICES.<CONSTANT> construct doesn't work.
Steps to reproduce.
>>> STATES = Choices(('ONLINE','1-2', 'Online'),('OFFLINE','2-1', 'Offline'),)
>>> STATES.constants
{'ONLINE': ('ONLINE', '1-2', 'Online'), 'OFFLINE': ('OFFLINE', '2-1', 'Offline')}
>>> STATES.ONLINE
'1-2'
>>> STATES = Choices(('1ONLINE','1-2', 'Online'),('2OFFLINE','2-1', 'Offline'),)
>>> STATES.constants
{'1ONLINE': ('1ONLINE', '1-2', 'Online'), '2OFFLINE': ('2OFFLINE', '2-1', 'Offline')}
>>> STATES.1ONLINE
File "<console>", line 1
STATES.1ONLINE
^
SyntaxError: invalid syntax
It's logic because the goal of the constant is to create an attribute. So it will never be possible, but it should raise an error at definition time.
Thanks for the report