On Thu, Apr 20, 2017 at 10:58 AM, Ethan Furman <[email protected]> wrote:
> I'm curious, what did you find ugly with:
>
> class TestEnum(CallableEnum):
>
> @enum
> def hello(text):
> "a pleasant greeting"
> print('hello,', text)
>
> @enum
> def goodbye(text):
> print('goodbye,', text)
>
Yeah, this is actually pretty reasonable.
For my use case, both the functions and their names are pretty long, so I
wouldn't want to write them inside the enum class. With a
decorator/function wrapper, it just gets kind of long -- especially if I
only import modules as required
<https://google.github.io/styleguide/pyguide.html?showone=Imports#Imports>
by the Google style guide. So my real usage looks more like:
class Greeting(callable_enum.Enum):
HELLO = callable_enum.Value(_greet_hello)
GOODBYE = callable_enum.Value(_greet_goodbye)
TO_PYTHON_IDEAS = callable_enum.Value(_welcome_to_python_ideas)
The large callable_enum.Value() wrappers make it harder to track what's
going on.
But perhaps this is really just a good use for an inline declaration, where
I don't need the wrappers at all:
Greeting = callable_enum.Enum('Greeting', {
'HELLO': _greet_hello,
'GOODBYE': _greet_goodbye,
'TO_PYTHON_IDEAS': _welcome_to_python_ideas,
})
_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/