File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -504,16 +504,28 @@ Data Types
504504
505505.. class :: StrEnum
506506
507- ``StrEnum `` is the same as :class: `Enum `, but its members are also strings and can be used
508- in most of the same places that a string can be used. The result of any string
509- operation performed on or with a *StrEnum * member is not part of the enumeration.
507+ *StrEnum * is the same as :class: `Enum `, but its members are also strings and
508+ can be used in most of the same places that a string can be used. The result
509+ of any string operation performed on or with a *StrEnum * member is not part
510+ of the enumeration.
511+
512+ >>> from enum import StrEnum
513+ >>> class Name (StrEnum ):
514+ ... IDENTIFIER = ' id'
515+ ... PROPERTY = ' pro'
516+ ... ATTRIBUTE = ' attr'
517+ ...
518+ >>> Name.IDENTIFIER
519+ <Name.IDENTIFIER: 'id'>
520+ >>> str (Name.IDENTIFIER )
521+ 'id'
510522
511523 .. note ::
512524
513525 There are places in the stdlib that check for an exact :class: `str `
514526 instead of a :class: `str ` subclass (i.e. ``type(unknown) == str ``
515527 instead of ``isinstance(unknown, str) ``), and in those locations you
516- will need to use ``str(StrEnum.member ) ``.
528+ will need to use ``str(MyStrEnum.MY_MEMBER ) ``.
517529
518530 .. note ::
519531
You can’t perform that action at this time.
0 commit comments