[Python-ideas] Classes inside functions [was Re: Add __parent__ to all classes, functions, and modules]

Ethan Furman ethan at stoneleaf.us
Mon Oct 6 17:43:10 CEST 2014


On 10/06/2014 08:07 AM, Andrew Barnert wrote:
> On Oct 5, 2014, at 20:04, Guido van Rossum wrote:
>>
>> The only non-evil use of this pattern that I can recall is in unit tests
>
> I agree that returning a class from a function is an uncommon special case, and any code that does so ought to have a
> good and obvious reason. But to say that such functions are evil doesn't seem right.
>
> What about [the] the two kinds of enums? Or a custom kind of enum (strings,
> bitsets, ...), which the PEP specifically suggests building on top of the stdlib support?

What do you mean?  Enums are classes, and the standard way to make new Enum types is by subclassing.

--
~Ethan~


More information about the Python-ideas mailing list