[issue31801] vars() manipulation encounters problems with Enum

2018-09-10 Thread Ethan Furman


Change by Ethan Furman :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31801] vars() manipulation encounters problems with Enum

2018-01-22 Thread Ethan Furman

Ethan Furman  added the comment:


New changeset a4b1bb4801f7a941ff9e86b96da539be1c288833 by Ethan Furman in 
branch 'master':
bpo-31801:  Enum:  add _ignore_ as class option (#5237)
https://github.com/python/cpython/commit/a4b1bb4801f7a941ff9e86b96da539be1c288833


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31801] vars() manipulation encounters problems with Enum

2018-01-18 Thread Ethan Furman

Change by Ethan Furman :


--
keywords: +patch
pull_requests: +5083
stage: needs patch -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31801] vars() manipulation encounters problems with Enum

2018-01-18 Thread Ethan Furman

Change by Ethan Furman :


--
stage: test needed -> needs patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31801] vars() manipulation encounters problems with Enum

2017-11-15 Thread Eric Wieser

Eric Wieser  added the comment:

Not necessarily an argument against this feature, but two workarounds exist for 
this already:


1. Use `nonlocal` to prevent `value` going into the class namespace:

value = None

class BaudRate(enum.Enum):
nonlocal value
for value in rates:
locals()['B%d' % value] = value

@classmethod
def valid_rate(cls, value):
return (any(value == item.value for item in cls))

2. Use `types.new_class`, which is more suited to dynamic class creation anyway:

def make_cls(ns):
for value in rates:
ns['B%d' % value] = value

@classmethod
def valid_rate(cls, value):
return (any(value == item.value for item in cls))

ns['valid_rate'] = valid_rate

types.new_class('BaudRate', (enum.Enum,), exec_body=make_cls)

--
nosy: +Eric.Wieser

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31801] vars() manipulation encounters problems with Enum

2017-10-16 Thread Ethan Furman

New submission from Ethan Furman :

The following code should work (from 
https://stackoverflow.com/a/46780742/208880):


class BaudRate(Enum):

cls = vars()
regexp = r"(?:^|,)B(?P\d+)"
rates = sorted(map(int, re.findall(regexp, ",".join(dir(termios)
for value in rates:
cls['B%d' % value] = value

@classmethod
def valid_rate(cls, value):
return (any(value == item.value for item in cls))


This doesn't work because EnumMeta does not allow names to be reassigned nor 
deleted.  aenum gets around this by allowing an _ignore_ attribute which 
contains the names that should not be tracked (and, in fact, those names are 
removed from the final class).

Unless a better idea is put forward, I will add _ignore_ support to Enum.

--
assignee: ethan.furman
messages: 304487
nosy: barry, eli.bendersky, ethan.furman
priority: normal
severity: normal
stage: test needed
status: open
title: vars() manipulation encounters problems with Enum
type: behavior
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com