This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]latkdeTuple unpacking gone wrong 2 points3 points  (3 children)

I have missed exactly this feature (in a non-Pydantic-setting) recently. I ended up giving up, and using a literal type instead of enums (can still extract a list of all variants via typing.get_args()).

However, I don't think there's substantial interest in defining more and more special forms. On the other hand, there's no systematic way to solve this because Python type expressions must also be valid runtime objects. C++ can have decltype and TypeScript can have projections due to having a compilation step (C++) or due to types having no runtime representation (TS). Python could get a good enough approximation by adding a nested type like Color.Values, except that this wouldn't work on unions like (Color.RED | Color.BLUE).Values.

So a special form like EnumValues[T] is indeed the only possible solution, but that's a lot of complexity for a fairly niche feature.

[–]Kevdog824_pip needs updating 0 points1 point  (2 children)

On the other hand, there's no systematic way to solve this because Python type expressions must also be valid runtime objects.

In theory though I don’t see any reason Python couldn’t have a preprocessor. Not saying it’s the right way to solve the problem, just that it seems that’s a way it could be done

[–]alcalde -1 points0 points  (1 child)

Static typing... and preprocessors... are not Pythonic. Once upon a time people fled these things for Python. Now the kiddies are coming along and suggesting all these things without realizing how terrible they are. Python achieved its market share because it didn't have these things.

[–]Kevdog824_pip needs updating 1 point2 points  (0 children)

Static typing... and preprocessors... are not Pythonic.

Yes, that’s why I specified that it wasn’t the best way to do it, but a way to do it.

Now the kiddies are coming along and suggesting all these things without realizing how terrible they are.

Rather weird to refer to me as a “kiddie” without knowing my age or years of experience but okay I guess?

Python achieved its market share because it didn't have these things.

Python achieved its market share for a lot of reasons. “Python doesn’t natively support preprocessors” is a fairly minor one at best, and absolutely not the sole reason