[Python-ideas] Change magic strings to enums

Chris Angelico rosuav at gmail.com
Wed Apr 25 05:46:20 EDT 2018


On Wed, Apr 25, 2018 at 7:12 PM, Jacco van Dorp <j.van.dorp at deonet.nl> wrote:
> Pycharm doesn't execute your code - it scans it. It wont know what you
> store on a function object.

How does it currently know what type something is? If you define
something using an enum, how is PyCharm going to know what the members
of that enum are?

> Forgive me if I misunderstand you, but aren't you really just trying
> to use those strings as enum members when you define a function like
> "takes one of these strings as argument" ? Because as far as I know,
> except from some fluff, that's exactly what enums are and are intended
> for - a unique set of keys that all have special meaning.

That's *one of* the things you can do with an enum. There are many
other features of enumerations, and I'm trying to boil your idea down
to its most compact form. You don't need all the power of Enum - you
just want to be able to list off the valid options.

ChrisA


More information about the Python-ideas mailing list