관리-도구
편집 파일: aenum.pdf
%PDF-1.4 %���� ReportLab Generated PDF document http://www.reportlab.com 1 0 obj << /F1 2 0 R /F2 3 0 R /F3 4 0 R /F4 5 0 R /F5 11 0 R >> endobj 2 0 obj << /BaseFont /Helvetica /Encoding /WinAnsiEncoding /Name /F1 /Subtype /Type1 /Type /Font >> endobj 3 0 obj << /BaseFont /Courier /Encoding /WinAnsiEncoding /Name /F2 /Subtype /Type1 /Type /Font >> endobj 4 0 obj << /BaseFont /Helvetica-Bold /Encoding /WinAnsiEncoding /Name /F3 /Subtype /Type1 /Type /Font >> endobj 5 0 obj << /BaseFont /Helvetica-BoldOblique /Encoding /WinAnsiEncoding /Name /F4 /Subtype /Type1 /Type /Font >> endobj 6 0 obj << /Border [ 0 0 0 ] /Contents () /Dest [ 25 0 R /XYZ 62.69291 768.5236 0 ] /Rect [ 326.1529 327.6772 452.7443 339.6772 ] /Subtype /Link /Type /Annot >> endobj 7 0 obj << /Annots [ 6 0 R ] /Contents 87 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 8 0 obj << /Border [ 0 0 0 ] /Contents () /Dest [ 40 0 R /XYZ 62.69291 667.5236 0 ] /Rect [ 128.2729 359.0236 228.8629 371.0236 ] /Subtype /Link /Type /Annot >> endobj 9 0 obj << /Annots [ 8 0 R ] /Contents 88 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 10 0 obj << /Border [ 0 0 0 ] /Contents () /Dest [ 25 0 R /XYZ 62.69291 768.5236 0 ] /Rect [ 252.7729 714.0236 360.1858 726.0236 ] /Subtype /Link /Type /Annot >> endobj 11 0 obj << /BaseFont /Helvetica-Oblique /Encoding /WinAnsiEncoding /Name /F5 /Subtype /Type1 /Type /Font >> endobj 12 0 obj << /Border [ 0 0 0 ] /Contents () /Dest [ 36 0 R /XYZ 62.69291 206.1236 0 ] /Rect [ 99.26291 449.8236 214.8629 461.8236 ] /Subtype /Link /Type /Annot >> endobj 13 0 obj << /Annots [ 10 0 R 12 0 R ] /Contents 89 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 14 0 obj << /Contents 90 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 15 0 obj << /Contents 91 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 16 0 obj << /Contents 92 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 17 0 obj << /Border [ 0 0 0 ] /Contents () /Dest [ 25 0 R /XYZ 62.69291 286.4236 0 ] /Rect [ 101.6029 382.4236 138.8429 394.4236 ] /Subtype /Link /Type /Annot >> endobj 18 0 obj << /Border [ 0 0 0 ] /Contents () /Dest [ 35 0 R /XYZ 62.69291 288.6236 0 ] /Rect [ 346.0429 226.2236 408.8429 238.2236 ] /Subtype /Link /Type /Annot >> endobj 19 0 obj << /Annots [ 17 0 R 18 0 R ] /Contents 93 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 20 0 obj << /Border [ 0 0 0 ] /Contents () /Dest [ 25 0 R /XYZ 62.69291 768.5236 0 ] /Rect [ 179.9829 632.8236 293.9503 644.8236 ] /Subtype /Link /Type /Annot >> endobj 21 0 obj << /Border [ 0 0 0 ] /Contents () /Dest [ 36 0 R /XYZ 62.69291 538.8236 0 ] /Rect [ 322.1329 129.4236 350.4829 141.4236 ] /Subtype /Link /Type /Annot >> endobj 22 0 obj << /Annots [ 20 0 R 21 0 R ] /Contents 94 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 23 0 obj << /Border [ 0 0 0 ] /Contents () /Dest [ 35 0 R /XYZ 62.69291 288.6236 0 ] /Rect [ 241.1229 368.4236 303.9229 380.4236 ] /Subtype /Link /Type /Annot >> endobj 24 0 obj << /Annots [ 23 0 R ] /Contents 95 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 25 0 obj << /Contents 96 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 26 0 obj << /Contents 97 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 27 0 obj << /Contents 98 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 28 0 obj << /Contents 99 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 29 0 obj << /Contents 100 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 30 0 obj << /Contents 101 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 31 0 obj << /Contents 102 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 32 0 obj << /Contents 103 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 33 0 obj << /Contents 104 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 34 0 obj << /Contents 105 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 35 0 obj << /Contents 106 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 36 0 obj << /Contents 107 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 37 0 obj << /Border [ 0 0 0 ] /Contents () /Dest [ 36 0 R /XYZ 62.69291 538.8236 0 ] /Rect [ 305.1229 214.8236 336.3283 226.8236 ] /Subtype /Link /Type /Annot >> endobj 38 0 obj << /Annots [ 37 0 R ] /Contents 108 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 39 0 obj << /Contents 109 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 40 0 obj << /Contents 110 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 41 0 obj << /Contents 111 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 42 0 obj << /Contents 112 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 43 0 obj << /Contents 113 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 44 0 obj << /Contents 114 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 86 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >> /Type /Page >> endobj 45 0 obj << /Outlines 47 0 R /PageLabels 115 0 R /PageMode /UseNone /Pages 86 0 R /Type /Catalog >> endobj 46 0 obj << /Author () /CreationDate (D:20230626171511+00'00') /Creator (\(unspecified\)) /Keywords () /ModDate (D:20230626171511+00'00') /Producer (ReportLab PDF Library - www.reportlab.com) /Subject (\(unspecified\)) /Title (aenum --- support for advanced enumerations, namedtuples, and constants) /Trapped /False >> endobj 47 0 obj << /Count 44 /First 48 0 R /Last 85 0 R /Type /Outlines >> endobj 48 0 obj << /Dest [ 7 0 R /XYZ 62.69291 450.6772 0 ] /Next 49 0 R /Parent 47 0 R /Title (Module Contents) >> endobj 49 0 obj << /Dest [ 13 0 R /XYZ 62.69291 765.0236 0 ] /Next 50 0 R /Parent 47 0 R /Prev 48 0 R /Title (Creating an Enum) >> endobj 50 0 obj << /Dest [ 15 0 R /XYZ 62.69291 498.8236 0 ] /Next 51 0 R /Parent 47 0 R /Prev 49 0 R /Title (Programmatic access to enumeration members and their attributes) >> endobj 51 0 obj << /Dest [ 15 0 R /XYZ 62.69291 143.2236 0 ] /Next 52 0 R /Parent 47 0 R /Prev 50 0 R /Title (Duplicating enum members and values) >> endobj 52 0 obj << /Dest [ 19 0 R /XYZ 62.69291 546.6236 0 ] /Next 53 0 R /Parent 47 0 R /Prev 51 0 R /Title (Comparisons) >> endobj 53 0 obj << /Dest [ 22 0 R /XYZ 62.69291 683.8236 0 ] /Next 54 0 R /Parent 47 0 R /Prev 52 0 R /Title (Allowed members and attributes of enumerations) >> endobj 54 0 obj << /Dest [ 24 0 R /XYZ 62.69291 765.0236 0 ] /Next 55 0 R /Parent 47 0 R /Prev 53 0 R /Title (Restricted Enum subclassing) >> endobj 55 0 obj << /Dest [ 24 0 R /XYZ 62.69291 356.4236 0 ] /Next 56 0 R /Parent 47 0 R /Prev 54 0 R /Title (Pickling) >> endobj 56 0 obj << /Dest [ 25 0 R /XYZ 62.69291 765.0236 0 ] /Next 57 0 R /Parent 47 0 R /Prev 55 0 R /Title (Enum Functional API) >> endobj 57 0 obj << /Count 4 /Dest [ 25 0 R /XYZ 62.69291 316.4236 0 ] /First 58 0 R /Last 61 0 R /Next 62 0 R /Parent 47 0 R /Prev 56 0 R /Title (Derived Enumerations) >> endobj 58 0 obj << /Dest [ 25 0 R /XYZ 62.69291 283.4236 0 ] /Next 59 0 R /Parent 57 0 R /Title (IntEnum) >> endobj 59 0 obj << /Dest [ 26 0 R /XYZ 62.69291 337.4236 0 ] /Next 60 0 R /Parent 57 0 R /Prev 58 0 R /Title (IntFlag) >> endobj 60 0 obj << /Dest [ 28 0 R /XYZ 62.69291 765.0236 0 ] /Next 61 0 R /Parent 57 0 R /Prev 59 0 R /Title (Flag) >> endobj 61 0 obj << /Dest [ 29 0 R /XYZ 62.69291 546.8236 0 ] /Parent 57 0 R /Prev 60 0 R /Title (Others) >> endobj 62 0 obj << /Count 8 /Dest [ 30 0 R /XYZ 62.69291 664.0236 0 ] /First 63 0 R /Last 70 0 R /Next 71 0 R /Parent 47 0 R /Prev 57 0 R /Title (Extra Goodies) >> endobj 63 0 obj << /Dest [ 30 0 R /XYZ 62.69291 613.0236 0 ] /Next 64 0 R /Parent 62 0 R /Title (enum) >> endobj 64 0 obj << /Dest [ 30 0 R /XYZ 62.69291 435.8236 0 ] /Next 65 0 R /Parent 62 0 R /Prev 63 0 R /Title (extend_enum) >> endobj 65 0 obj << /Dest [ 31 0 R /XYZ 62.69291 667.8236 0 ] /Next 66 0 R /Parent 62 0 R /Prev 64 0 R /Title (constant) >> endobj 66 0 obj << /Dest [ 31 0 R /XYZ 62.69291 298.6236 0 ] /Next 67 0 R /Parent 62 0 R /Prev 65 0 R /Title (skip) >> endobj 67 0 obj << /Dest [ 32 0 R /XYZ 62.69291 765.0236 0 ] /Next 68 0 R /Parent 62 0 R /Prev 66 0 R /Title (start) >> endobj 68 0 obj << /Dest [ 32 0 R /XYZ 62.69291 486.6236 0 ] /Next 69 0 R /Parent 62 0 R /Prev 67 0 R /Title (init) >> endobj 69 0 obj << /Dest [ 32 0 R /XYZ 62.69291 128.4236 0 ] /Next 70 0 R /Parent 62 0 R /Prev 68 0 R /Title (init and missing values) >> endobj 70 0 obj << /Dest [ 33 0 R /XYZ 62.69291 395.8599 0 ] /Parent 62 0 R /Prev 69 0 R /Title (combining Flag with other data types) >> endobj 71 0 obj << /Count 1 /Dest [ 34 0 R /XYZ 62.69291 594.8236 0 ] /First 72 0 R /Last 72 0 R /Next 73 0 R /Parent 47 0 R /Prev 62 0 R /Title (Decorators) >> endobj 72 0 obj << /Dest [ 34 0 R /XYZ 62.69291 561.8236 0 ] /Parent 71 0 R /Title (unique) >> endobj 73 0 obj << /Count 4 /Dest [ 34 0 R /XYZ 62.69291 384.6236 0 ] /First 74 0 R /Last 77 0 R /Next 78 0 R /Parent 47 0 R /Prev 71 0 R /Title (Interesting examples) >> endobj 74 0 obj << /Dest [ 34 0 R /XYZ 62.69291 309.6236 0 ] /Next 75 0 R /Parent 73 0 R /Title (AutoNumber) >> endobj 75 0 obj << /Dest [ 35 0 R /XYZ 62.69291 582.8236 0 ] /Next 76 0 R /Parent 73 0 R /Prev 74 0 R /Title (UniqueEnum) >> endobj 76 0 obj << /Dest [ 35 0 R /XYZ 62.69291 285.6236 0 ] /Next 77 0 R /Parent 73 0 R /Prev 75 0 R /Title (OrderedEnum) >> endobj 77 0 obj << /Dest [ 36 0 R /XYZ 62.69291 535.8236 0 ] /Parent 73 0 R /Prev 76 0 R /Title (Planet) >> endobj 78 0 obj << /Count 3 /Dest [ 36 0 R /XYZ 62.69291 202.6236 0 ] /First 79 0 R /Last 81 0 R /Next 82 0 R /Parent 47 0 R /Prev 73 0 R /Title (How are Enums different?) >> endobj 79 0 obj << /Dest [ 38 0 R /XYZ 62.69291 765.0236 0 ] /Next 80 0 R /Parent 78 0 R /Title (Enum Classes) >> endobj 80 0 obj << /Dest [ 38 0 R /XYZ 62.69291 568.0236 0 ] /Next 81 0 R /Parent 78 0 R /Prev 79 0 R /Title (Enum Members \(aka instances\)) >> endobj 81 0 obj << /Dest [ 38 0 R /XYZ 62.69291 496.0236 0 ] /Parent 78 0 R /Prev 80 0 R /Title (Finer Points) >> endobj 82 0 obj << /Count 2 /Dest [ 40 0 R /XYZ 62.69291 664.0236 0 ] /First 83 0 R /Last 84 0 R /Next 85 0 R /Parent 47 0 R /Prev 78 0 R /Title (Creating NamedTuples) >> endobj 83 0 obj << /Dest [ 40 0 R /XYZ 62.69291 631.0236 0 ] /Next 84 0 R /Parent 82 0 R /Title (Simple) >> endobj 84 0 obj << /Dest [ 41 0 R /XYZ 62.69291 475.8236 0 ] /Parent 82 0 R /Prev 83 0 R /Title (Advanced) >> endobj 85 0 obj << /Dest [ 43 0 R /XYZ 62.69291 236.2236 0 ] /Parent 47 0 R /Prev 82 0 R /Title (Creating NamedConstants) >> endobj 86 0 obj << /Count 28 /Kids [ 7 0 R 9 0 R 13 0 R 14 0 R 15 0 R 16 0 R 19 0 R 22 0 R 24 0 R 25 0 R 26 0 R 27 0 R 28 0 R 29 0 R 30 0 R 31 0 R 32 0 R 33 0 R 34 0 R 35 0 R 36 0 R 38 0 R 39 0 R 40 0 R 41 0 R 42 0 R 43 0 R 44 0 R ] /Type /Pages >> endobj 87 0 obj << /Length 4842 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 717.0236 cm q BT 1 0 0 1 0 28 Tm 16.02488 0 Td 24 TL /F2 20 Tf 0 0 0 rg (aenum) Tj /F3 20 Tf ( --- support for advanced enumerations,) Tj T* 83.89 0 Td (namedtuples, and constants) Tj T* -99.91488 0 Td ET Q Q q 1 0 0 1 62.69291 678.6772 cm n 0 14.17323 m 469.8898 14.17323 l S Q q 1 0 0 1 62.69291 648.6772 cm q BT 1 0 0 1 0 14 Tm .11311 Tw 12 TL /F1 10 Tf 0 0 0 rg (An ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( is a set of symbolic names \(members\) bound to unique, constant values. Within an enumeration,) Tj T* 0 Tw (the members can be compared by identity, and the enumeration itself can be iterated over.) Tj T* ET Q Q q 1 0 0 1 62.69291 618.6772 cm q BT 1 0 0 1 0 14 Tm 1.607126 Tw 12 TL /F1 10 Tf 0 0 0 rg (A ) Tj /F2 10 Tf (NamedTuple) Tj /F1 10 Tf ( is a class-based, fixed-length tuple with a name for each possible position accessible) Tj T* 0 Tw (using attribute-access notation.) Tj T* ET Q Q q 1 0 0 1 62.69291 564.6772 cm q BT 1 0 0 1 0 38 Tm 1.331318 Tw 12 TL /F1 10 Tf 0 0 0 rg (A ) Tj /F2 10 Tf (NamedConstant) Tj /F1 10 Tf ( is a class whose members cannot be rebound; it lacks all other ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( capabilities,) Tj T* 0 Tw .57686 Tw (however; consequently, it can have duplicate values. There is also a ) Tj /F2 10 Tf (module) Tj /F1 10 Tf ( function that can insert the) Tj T* 0 Tw 1.165697 Tw /F2 10 Tf (NamedConstant) Tj /F1 10 Tf ( class into ) Tj /F2 10 Tf (sys.modules) Tj /F1 10 Tf ( where it will appear to be a module whose top-level names) Tj T* 0 Tw (cannot be rebound.) Tj T* ET Q Q q 1 0 0 1 62.69291 552.6772 cm Q q 1 0 0 1 62.69291 468.6772 cm .960784 .960784 .862745 rg n 0 84 469.8898 -84 re f* 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 6 58 Tm T* ET q 1 0 0 1 16 53 cm q 0 0 0 rg BT 1 0 0 1 0 2.5 Tm /F4 12.5 Tf 15 TL (Note) Tj T* ET Q Q q 1 0 0 1 16 31 cm q BT 1 0 0 1 0 2 Tm 12 TL /F2 10 Tf 0 0 0 rg (constant) Tj /F3 10 Tf ( refers to names not being rebound; mutable objects can be) Tj T* ET Q Q q 1 0 0 1 16 16 cm 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 0 2 Tm T* ET q 1 0 0 1 20 0 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (mutated.) Tj T* ET Q Q q Q Q q 1 J 1 j .662745 .662745 .662745 RG .5 w n 0 84 m 469.8898 84 l S n 0 0 m 469.8898 0 l S n 0 0 m 0 84 l S n 469.8898 0 m 469.8898 84 l S Q Q q 1 0 0 1 62.69291 462.6772 cm Q q 1 0 0 1 62.69291 429.6772 cm q BT 1 0 0 1 0 3.5 Tm 21 TL /F3 17.5 Tf 0 0 0 rg (Module Contents) Tj T* ET Q Q q 1 0 0 1 62.69291 399.6772 cm q BT 1 0 0 1 0 14 Tm -0.118837 Tw 12 TL /F1 10 Tf 0 0 0 rg (This module defines five enumeration classes that can be used to define unique sets of names and values,) Tj T* 0 Tw (one ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( class decorator, one ) Tj /F2 10 Tf (NamedTuple) Tj /F1 10 Tf ( class, one ) Tj /F2 10 Tf (NamedConstant) Tj /F1 10 Tf ( class, and several helpers.) Tj T* ET Q Q q 1 0 0 1 62.69291 381.6772 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F2 10 Tf 12 TL (NamedConstant) Tj T* ET Q Q q 1 0 0 1 62.69291 363.6772 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (NamedConstant class for creating groups of constants. These names cannot be rebound to other values.) Tj T* ET Q Q q 1 0 0 1 62.69291 345.6772 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F2 10 Tf 12 TL (Enum) Tj T* ET Q Q q 1 0 0 1 62.69291 315.6772 cm q BT 1 0 0 1 0 14 Tm 3.266136 Tw 12 TL /F1 10 Tf 0 0 0 rg (Base class for creating enumerated constants. See section ) Tj 0 0 .501961 rg (Enum Functional API) Tj 0 0 0 rg ( for an alternate) Tj T* 0 Tw (construction syntax.) Tj T* ET Q Q q 1 0 0 1 62.69291 297.6772 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F2 10 Tf 12 TL (AddValue) Tj T* ET Q Q q 1 0 0 1 62.69291 267.6772 cm q BT 1 0 0 1 0 14 Tm .187126 Tw 12 TL /F1 10 Tf 0 0 0 rg (Flag specifying that ) Tj /F2 10 Tf (_generate_next_value_) Tj /F1 10 Tf ( should always be called to provide the initial value for an) Tj T* 0 Tw (enum member.) Tj T* ET Q Q q 1 0 0 1 62.69291 249.6772 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F2 10 Tf 12 TL (MultiValue) Tj T* ET Q Q q 1 0 0 1 62.69291 219.6772 cm q 0 0 0 rg BT 1 0 0 1 0 14 Tm /F1 10 Tf 12 TL .205988 Tw (Flag specifying that each item of tuple value is a separate value for that member; the first tuple item is the) Tj T* 0 Tw (canonical one.) Tj T* ET Q Q q 1 0 0 1 62.69291 201.6772 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F2 10 Tf 12 TL (NoAlias) Tj T* ET Q Q q 1 0 0 1 62.69291 183.6772 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (Flag specifying that duplicate valued members are distinct and not aliases; by-value lookups are disabled.) Tj T* ET Q Q q 1 0 0 1 62.69291 165.6772 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F2 10 Tf 12 TL (Unique) Tj T* ET Q Q q 1 0 0 1 62.69291 147.6772 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (Flag specifying that duplicate valued members are not allowed.) Tj T* ET Q Q q 1 0 0 1 62.69291 135.6772 cm Q endstream endobj 88 0 obj << /Length 5767 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 682.0236 cm .960784 .960784 .862745 rg n 0 83 469.8898 -83 re f* 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 6 57 Tm T* ET q 1 0 0 1 16 52 cm q 0 0 0 rg BT 1 0 0 1 0 2.5 Tm /F4 12.5 Tf 15 TL (Note) Tj T* ET Q Q q 1 0 0 1 16 16 cm q BT 1 0 0 1 0 14 Tm 2.274651 Tw 12 TL /F1 10 Tf 0 0 0 rg (The flags are inherited by the enumeration's subclasses. To use them in Python 2 assign to) Tj T* 0 Tw /F2 10 Tf (_settings_) Tj /F1 10 Tf ( in the class body.) Tj T* ET Q Q q 1 J 1 j .662745 .662745 .662745 RG .5 w n 0 83 m 469.8898 83 l S n 0 0 m 469.8898 0 l S n 0 0 m 0 83 l S n 469.8898 0 m 469.8898 83 l S Q Q q 1 0 0 1 62.69291 676.0236 cm Q q 1 0 0 1 62.69291 658.0236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F2 10 Tf 12 TL (IntEnum) Tj T* ET Q Q q 1 0 0 1 62.69291 640.0236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (Base class for creating enumerated constants that are also subclasses of ) Tj /F2 10 Tf (int) Tj /F1 10 Tf (.) Tj T* ET Q Q q 1 0 0 1 62.69291 622.0236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F2 10 Tf 12 TL (AutoNumberEnum) Tj T* ET Q Q q 1 0 0 1 62.69291 604.0236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (Derived class that automatically assigns an ) Tj /F2 10 Tf (int) Tj /F1 10 Tf ( value to each member.) Tj T* ET Q Q q 1 0 0 1 62.69291 586.0236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F2 10 Tf 12 TL (OrderedEnum) Tj T* ET Q Q q 1 0 0 1 62.69291 568.0236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (Derived class that adds ) Tj /F2 10 Tf (<) Tj /F1 10 Tf (, ) Tj /F2 10 Tf (<) Tj (=) Tj /F1 10 Tf (, ) Tj /F2 10 Tf (>) Tj (=) Tj /F1 10 Tf (, and ) Tj /F2 10 Tf (>) Tj /F1 10 Tf ( methods to an ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf (.) Tj T* ET Q Q q 1 0 0 1 62.69291 550.0236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F2 10 Tf 12 TL (UniqueEnum) Tj T* ET Q Q q 1 0 0 1 62.69291 532.0236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (Derived class that ensures only one name is bound to any one value.) Tj T* ET Q Q q 1 0 0 1 62.69291 514.0236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F2 10 Tf 12 TL (unique) Tj T* ET Q Q q 1 0 0 1 62.69291 496.0236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (Enum class decorator that ensures only one name is bound to any one value.) Tj T* ET Q Q q 1 0 0 1 62.69291 484.0236 cm Q q 1 0 0 1 62.69291 401.0236 cm .960784 .960784 .862745 rg n 0 83 469.8898 -83 re f* 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 6 57 Tm T* ET q 1 0 0 1 16 52 cm q 0 0 0 rg BT 1 0 0 1 0 2.5 Tm /F4 12.5 Tf 15 TL (Note) Tj T* ET Q Q q 1 0 0 1 16 16 cm q BT 1 0 0 1 0 14 Tm .592485 Tw 12 TL /F1 10 Tf 0 0 0 rg (the ) Tj /F2 10 Tf (UniqueEnum) Tj /F1 10 Tf ( class, the ) Tj /F2 10 Tf (unique) Tj /F1 10 Tf ( decorator, and the Unique flag all do the same thing; you do) Tj T* 0 Tw (not need to use more than one of them at the same time.) Tj T* ET Q Q q 1 J 1 j .662745 .662745 .662745 RG .5 w n 0 83 m 469.8898 83 l S n 0 0 m 469.8898 0 l S n 0 0 m 0 83 l S n 469.8898 0 m 469.8898 83 l S Q Q q 1 0 0 1 62.69291 395.0236 cm Q q 1 0 0 1 62.69291 377.0236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F2 10 Tf 12 TL (NamedTuple) Tj T* ET Q Q q 1 0 0 1 62.69291 359.0236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (Base class for ) Tj 0 0 .501961 rg (creating NamedTuples) Tj 0 0 0 rg (, either by subclassing or via it's functional API.) Tj T* ET Q Q q 1 0 0 1 62.69291 341.0236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F2 10 Tf 12 TL (constant) Tj T* ET Q Q q 1 0 0 1 62.69291 323.0236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (Descriptor to add constant values to an ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf (, or advanced constants to ) Tj /F2 10 Tf (NamedConstant) Tj /F1 10 Tf (.) Tj T* ET Q Q q 1 0 0 1 62.69291 305.0236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F2 10 Tf 12 TL (convert) Tj T* ET Q Q q 1 0 0 1 62.69291 287.0236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (Helper to transform target global variables into an ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf (.) Tj T* ET Q Q q 1 0 0 1 62.69291 269.0236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F2 10 Tf 12 TL (enum) Tj T* ET Q Q q 1 0 0 1 62.69291 251.0236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (Helper for specifying keyword arguments when creating ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( members.) Tj T* ET Q Q q 1 0 0 1 62.69291 233.0236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F2 10 Tf 12 TL (export) Tj T* ET Q Q q 1 0 0 1 62.69291 203.0236 cm q BT 1 0 0 1 0 14 Tm 4.493615 Tw 12 TL /F1 10 Tf 0 0 0 rg (Helper for inserting ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( members and ) Tj /F2 10 Tf (NamedConstant) Tj /F1 10 Tf ( constants into a namespace \(usually) Tj T* 0 Tw /F2 10 Tf (globals\(\)) Tj /F1 10 Tf (.) Tj T* ET Q Q q 1 0 0 1 62.69291 185.0236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F2 10 Tf 12 TL (extend_enum) Tj T* ET Q Q q 1 0 0 1 62.69291 167.0236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (Helper for adding new ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( members, both stdlib and aenum.) Tj T* ET Q Q q 1 0 0 1 62.69291 149.0236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F2 10 Tf 12 TL (module) Tj T* ET Q Q q 1 0 0 1 62.69291 119.0236 cm q BT 1 0 0 1 0 14 Tm 1.148221 Tw 12 TL /F1 10 Tf 0 0 0 rg (Function to take a ) Tj /F2 10 Tf (NamedConstant) Tj /F1 10 Tf ( or ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( class and insert it into ) Tj /F2 10 Tf (sys.modules) Tj /F1 10 Tf ( with the affect of a) Tj T* 0 Tw (module whose top-level constant and member names cannot be rebound.) Tj T* ET Q Q q 1 0 0 1 62.69291 101.0236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F2 10 Tf 12 TL (skip) Tj T* ET Q Q q 1 0 0 1 62.69291 83.02362 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (Descriptor to add a normal \(non-) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( member\) attribute to an ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( or ) Tj /F2 10 Tf (NamedConstant) Tj /F1 10 Tf (.) Tj T* ET Q Q endstream endobj 89 0 obj << /Length 5850 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 744.0236 cm q BT 1 0 0 1 0 3.5 Tm 21 TL /F3 17.5 Tf 0 0 0 rg (Creating an Enum) Tj T* ET Q Q q 1 0 0 1 62.69291 702.0236 cm q BT 1 0 0 1 0 26 Tm 2.647318 Tw 12 TL /F1 10 Tf 0 0 0 rg (Enumerations are created using the ) Tj /F2 10 Tf (class) Tj /F1 10 Tf ( syntax, which makes them easy to read and write. An) Tj T* 0 Tw 1.685366 Tw (alternative creation method is described in ) Tj 0 0 .501961 rg (Enum Functional API) Tj 0 0 0 rg (. To define an enumeration, subclass) Tj T* 0 Tw /F2 10 Tf (Enum) Tj /F1 10 Tf ( as follows:) Tj T* ET Q Q q 1 0 0 1 62.69291 620.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 72 re B* Q q BT 1 0 0 1 0 50 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( from aenum import Enum) Tj T* (>) Tj (>) Tj (>) Tj ( class Color\(Enum\):) Tj T* (... red = 1) Tj T* (... green = 2) Tj T* (... blue = 3) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 600.8236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F5 10 Tf 12 TL (Nomenclature) Tj T* ET Q Q q 1 0 0 1 62.69291 594.8236 cm Q q 1 0 0 1 62.69291 528.8236 cm 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 0 2 Tm T* ET q 1 0 0 1 20 60 cm Q q 1 0 0 1 20 60 cm Q q 1 0 0 1 20 48 cm 0 0 0 rg BT /F1 10 Tf 12 TL ET q 1 0 0 1 6 -3 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL 10.5 0 Td (\177) Tj T* -10.5 0 Td ET Q Q q 1 0 0 1 23 -3 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (The class ) Tj /F2 10 Tf (Color) Tj /F1 10 Tf ( is an ) Tj /F5 10 Tf (enumeration) Tj /F1 10 Tf ( \(or ) Tj /F5 10 Tf (enum) Tj /F1 10 Tf (\)) Tj T* ET Q Q q Q Q q 1 0 0 1 20 42 cm Q q 1 0 0 1 20 30 cm 0 0 0 rg BT /F1 10 Tf 12 TL ET q 1 0 0 1 6 -3 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL 10.5 0 Td (\177) Tj T* -10.5 0 Td ET Q Q q 1 0 0 1 23 -3 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (The attributes ) Tj /F2 10 Tf (Color.red) Tj /F1 10 Tf (, ) Tj /F2 10 Tf (Color.green) Tj /F1 10 Tf (, etc., are ) Tj /F5 10 Tf (enumeration members) Tj /F1 10 Tf ( \(or ) Tj /F5 10 Tf (enum members) Tj /F1 10 Tf (\).) Tj T* ET Q Q q Q Q q 1 0 0 1 20 24 cm Q q 1 0 0 1 20 0 cm 0 0 0 rg BT /F1 10 Tf 12 TL ET q 1 0 0 1 6 9 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL 10.5 0 Td (\177) Tj T* -10.5 0 Td ET Q Q q 1 0 0 1 23 -3 cm q BT 1 0 0 1 0 14 Tm 1.685984 Tw 12 TL /F1 10 Tf 0 0 0 rg (The enum members have ) Tj /F5 10 Tf (names) Tj /F1 10 Tf ( and ) Tj /F5 10 Tf (values) Tj /F1 10 Tf ( \(the name of ) Tj /F2 10 Tf (Color.red) Tj /F1 10 Tf ( is ) Tj /F2 10 Tf (red) Tj /F1 10 Tf (, the value of) Tj T* 0 Tw /F2 10 Tf (Color.blue) Tj /F1 10 Tf ( is ) Tj /F2 10 Tf (3) Tj /F1 10 Tf (, etc.\)) Tj T* ET Q Q q Q Q q 1 0 0 1 20 0 cm Q q Q Q q 1 0 0 1 62.69291 528.8236 cm Q q 1 0 0 1 62.69291 516.8236 cm Q q 1 0 0 1 62.69291 433.8236 cm .960784 .960784 .862745 rg n 0 83 469.8898 -83 re f* 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 6 57 Tm T* ET q 1 0 0 1 16 52 cm q 0 0 0 rg BT 1 0 0 1 0 2.5 Tm /F4 12.5 Tf 15 TL (Note) Tj T* ET Q Q q 1 0 0 1 16 16 cm q BT 1 0 0 1 0 14 Tm .920651 Tw 12 TL /F1 10 Tf 0 0 0 rg (Even though we use the ) Tj /F2 10 Tf (class) Tj /F1 10 Tf ( syntax to create Enums, Enums are not normal Python classes.) Tj T* 0 Tw (See ) Tj 0 0 .501961 rg (How are Enums different?) Tj 0 0 0 rg ( for more details.) Tj T* ET Q Q q 1 J 1 j .662745 .662745 .662745 RG .5 w n 0 83 m 469.8898 83 l S n 0 0 m 469.8898 0 l S n 0 0 m 0 83 l S n 469.8898 0 m 469.8898 83 l S Q Q q 1 0 0 1 62.69291 427.8236 cm Q q 1 0 0 1 62.69291 409.8236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (Enumeration members have human readable string representations:) Tj T* ET Q Q q 1 0 0 1 62.69291 364.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 36 re B* Q q BT 1 0 0 1 0 14 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( print\(Color.red\)) Tj T* (Color.red) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 344.6236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (...while their ) Tj /F2 10 Tf (repr) Tj /F1 10 Tf ( has more information:) Tj T* ET Q Q q 1 0 0 1 62.69291 299.4236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 36 re B* Q q BT 1 0 0 1 0 14 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( print\(repr\(Color.red\)\)) Tj T* (<) Tj (Color.red: 1) Tj (>) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 279.4236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (The ) Tj /F5 10 Tf (type) Tj /F1 10 Tf ( of an enumeration member is the enumeration it belongs to:) Tj T* ET Q Q q 1 0 0 1 62.69291 210.2236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 60 re B* Q q BT 1 0 0 1 0 38 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( type\(Color.red\)) Tj T* (<) Tj (aenum 'Color') Tj (>) Tj T* (>) Tj (>) Tj (>) Tj ( isinstance\(Color.green, Color\)) Tj T* (True) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 166.2236 cm q BT 1 0 0 1 0 26 Tm .464985 Tw 12 TL /F1 10 Tf 0 0 0 rg (Enumerations support iteration. In Python 3.x definition order is used; in Python 2.x the definition order is) Tj T* 0 Tw -0.079349 Tw (not available, but class attribute ) Tj /F2 10 Tf (_order_) Tj /F1 10 Tf ( is supported; otherwise, value order is used if posible, otherwise) Tj T* 0 Tw (alphabetical name order is used:) Tj T* ET Q Q q 1 0 0 1 62.69291 85.02362 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 72 re B* Q q BT 1 0 0 1 0 50 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class Shake\(Enum\):) Tj T* (... _order_ = 'vanilla chocolate cookies mint' # only needed in 2.x) Tj T* (... vanilla = 7) Tj T* (... chocolate = 4) Tj T* (... cookies = 9) Tj T* ET Q Q Q Q Q endstream endobj 90 0 obj << /Length 3944 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 643.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 120 re B* Q q BT 1 0 0 1 0 98 Tm 12 TL /F2 10 Tf 0 0 0 rg (... mint = 3) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( for shake in Shake:) Tj T* (... print\(shake\)) Tj T* (...) Tj T* (Shake.vanilla) Tj T* (Shake.chocolate) Tj T* (Shake.cookies) Tj T* (Shake.mint) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 611.8236 cm q BT 1 0 0 1 0 14 Tm 1.13683 Tw 12 TL /F1 10 Tf 0 0 0 rg (The ) Tj /F2 10 Tf (_order_) Tj /F1 10 Tf ( attribute is always removed, but in 3.x it is also used to verify that definition order is the) Tj T* 0 Tw (same \(useful for py2) Tj (&) Tj (3 code bases\); however, in the stdlib version it will be ignored and not removed.) Tj T* ET Q Q q 1 0 0 1 62.69291 599.8236 cm Q q 1 0 0 1 62.69291 516.8236 cm .960784 .960784 .862745 rg n 0 83 469.8898 -83 re f* 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 6 57 Tm T* ET q 1 0 0 1 16 52 cm q 0 0 0 rg BT 1 0 0 1 0 2.5 Tm /F4 12.5 Tf 15 TL (Note) Tj T* ET Q Q q 1 0 0 1 16 16 cm q 0 0 0 rg BT 1 0 0 1 0 14 Tm /F1 10 Tf 12 TL 1.915366 Tw (To maintain compatibility with Python 3.4 and 3.5, use __order__ instead \(double leading and) Tj T* 0 Tw (trailing underscores\).) Tj T* ET Q Q q 1 J 1 j .662745 .662745 .662745 RG .5 w n 0 83 m 469.8898 83 l S n 0 0 m 469.8898 0 l S n 0 0 m 0 83 l S n 469.8898 0 m 469.8898 83 l S Q Q q 1 0 0 1 62.69291 510.8236 cm Q q 1 0 0 1 62.69291 492.8236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (Enumeration members are hashable, so they can be used in dictionaries and sets:) Tj T* ET Q Q q 1 0 0 1 62.69291 411.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 72 re B* Q q BT 1 0 0 1 0 50 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( apples = {}) Tj T* (>) Tj (>) Tj (>) Tj ( apples[Color.red] = 'red delicious') Tj T* (>) Tj (>) Tj (>) Tj ( apples[Color.green] = 'granny smith') Tj T* (>) Tj (>) Tj (>) Tj ( apples == {Color.red: 'red delicious', Color.green: 'granny smith'}) Tj T* (True) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 391.6236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (In Python 3 the class syntax has a few extra advancements:) Tj T* ET Q Q q 1 0 0 1 62.69291 286.4236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 96 re B* Q q BT 1 0 0 1 0 74 Tm 12 TL /F2 10 Tf 0 0 0 rg (--) Tj (>) Tj ( class Color\() Tj T* (... Enum,) Tj T* (... settings=\(AddValue, MultiValue, NoAlias, Unique\),) Tj T* (... init='field_name1 field_name2 ...',) Tj T* (... start=7,) Tj T* (... \)) Tj T* (...) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 266.4236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F2 10 Tf 0 0 0 rg (start) Tj /F1 10 Tf ( is used to specify the starting value for the first member:) Tj T* ET Q Q q 1 0 0 1 62.69291 173.2236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 84 re B* Q q BT 1 0 0 1 0 62 Tm 12 TL /F2 10 Tf 0 0 0 rg (--) Tj (>) Tj ( class Count\(Enum, start=11\):) Tj T* (... eleven) Tj T* (... twelve) Tj T* (...) Tj T* (--) Tj (>) Tj ( Count.twelve.value == 12) Tj T* (True) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 153.2236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F2 10 Tf 0 0 0 rg (init) Tj /F1 10 Tf ( specifies the attribute names to store creation values to:) Tj T* ET Q Q q 1 0 0 1 62.69291 84.02362 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 60 re B* Q q BT 1 0 0 1 0 38 Tm 12 TL /F2 10 Tf 0 0 0 rg (--) Tj (>) Tj ( class Planet\(Enum, init='mass radius'\):) Tj T* (... MERCURY = \(3.303e+23, 2.4397e6\)) Tj T* (... EARTH = \(5.976e+24, 6.37814e6\)) Tj T* (...) Tj T* ET Q Q Q Q Q endstream endobj 91 0 obj << /Length 5378 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 703.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 60 re B* Q q BT 1 0 0 1 0 38 Tm 12 TL /F2 10 Tf 0 0 0 rg (--) Tj (>) Tj ( Planet.EARTH.value) Tj T* (\(5.976e+24, 6378140.0\)) Tj T* (--) Tj (>) Tj ( Planet.EARTH.radius) Tj T* (2.4397e6) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 683.8236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (The various settings enable special behavior:) Tj T* ET Q Q q 1 0 0 1 62.69291 677.8236 cm Q q 1 0 0 1 62.69291 677.8236 cm Q q 1 0 0 1 62.69291 665.8236 cm 0 0 0 rg BT /F1 10 Tf 12 TL ET q 1 0 0 1 6 -3 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL 10.5 0 Td (\177) Tj T* -10.5 0 Td ET Q Q q 1 0 0 1 23 -3 cm q BT 1 0 0 1 0 2 Tm 12 TL /F2 10 Tf 0 0 0 rg (AddValue) Tj /F1 10 Tf ( calls a user supplied ) Tj /F2 10 Tf (_generate_next_value_) Tj /F1 10 Tf ( to provide the initial value) Tj T* ET Q Q q Q Q q 1 0 0 1 62.69291 659.8236 cm Q q 1 0 0 1 62.69291 647.8236 cm 0 0 0 rg BT /F1 10 Tf 12 TL ET q 1 0 0 1 6 -3 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL 10.5 0 Td (\177) Tj T* -10.5 0 Td ET Q Q q 1 0 0 1 23 -3 cm q BT 1 0 0 1 0 2 Tm 12 TL /F2 10 Tf 0 0 0 rg (MultiValue) Tj /F1 10 Tf ( allows multiple values per member instead of the usual 1) Tj T* ET Q Q q Q Q q 1 0 0 1 62.69291 641.8236 cm Q q 1 0 0 1 62.69291 629.8236 cm 0 0 0 rg BT /F1 10 Tf 12 TL ET q 1 0 0 1 6 -3 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL 10.5 0 Td (\177) Tj T* -10.5 0 Td ET Q Q q 1 0 0 1 23 -3 cm q BT 1 0 0 1 0 2 Tm 12 TL /F2 10 Tf 0 0 0 rg (NoAlias) Tj /F1 10 Tf ( allows different members to have the same value) Tj T* ET Q Q q Q Q q 1 0 0 1 62.69291 623.8236 cm Q q 1 0 0 1 62.69291 611.8236 cm 0 0 0 rg BT /F1 10 Tf 12 TL ET q 1 0 0 1 6 -3 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL 10.5 0 Td (\177) Tj T* -10.5 0 Td ET Q Q q 1 0 0 1 23 -3 cm q BT 1 0 0 1 0 2 Tm 12 TL /F2 10 Tf 0 0 0 rg (Unique) Tj /F1 10 Tf ( disallows different members to have the same value) Tj T* ET Q Q q Q Q q 1 0 0 1 62.69291 611.8236 cm Q q 1 0 0 1 62.69291 599.8236 cm Q q 1 0 0 1 62.69291 516.8236 cm .960784 .960784 .862745 rg n 0 83 469.8898 -83 re f* 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 6 57 Tm T* ET q 1 0 0 1 16 52 cm q 0 0 0 rg BT 1 0 0 1 0 2.5 Tm /F4 12.5 Tf 15 TL (Note) Tj T* ET Q Q q 1 0 0 1 16 16 cm q BT 1 0 0 1 0 14 Tm .973516 Tw 12 TL /F1 10 Tf 0 0 0 rg (To use these features in Python 2 use the _sundered_ versions of the names in the class body:) Tj T* 0 Tw /F2 10 Tf (_start_) Tj /F1 10 Tf (, ) Tj /F2 10 Tf (_init_) Tj /F1 10 Tf (, ) Tj /F2 10 Tf (_settings_) Tj /F1 10 Tf (.) Tj T* ET Q Q q 1 J 1 j .662745 .662745 .662745 RG .5 w n 0 83 m 469.8898 83 l S n 0 0 m 469.8898 0 l S n 0 0 m 0 83 l S n 469.8898 0 m 469.8898 83 l S Q Q q 1 0 0 1 62.69291 510.8236 cm Q q 1 0 0 1 62.69291 456.8236 cm q BT 1 0 0 1 0 24.5 Tm 21 TL /F3 17.5 Tf 0 0 0 rg (Programmatic access to enumeration members and) Tj T* (their attributes) Tj T* ET Q Q q 1 0 0 1 62.69291 414.8236 cm q BT 1 0 0 1 0 26 Tm 3.541797 Tw 12 TL /F1 10 Tf 0 0 0 rg (Sometimes it's useful to access members in enumerations programmatically \(i.e. situations where) Tj T* 0 Tw 1.137318 Tw /F2 10 Tf (Color.red) Tj /F1 10 Tf ( won't do because the exact color is not known at program-writing time\). ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( allows such) Tj T* 0 Tw (access:) Tj T* ET Q Q q 1 0 0 1 62.69291 345.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 60 re B* Q q BT 1 0 0 1 0 38 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( Color\(1\)) Tj T* (<) Tj (Color.red: 1) Tj (>) Tj T* (>) Tj (>) Tj (>) Tj ( Color\(3\)) Tj T* (<) Tj (Color.blue: 3) Tj (>) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 325.6236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (If you want to access enum members by ) Tj /F5 10 Tf (name) Tj /F1 10 Tf (, use item access:) Tj T* ET Q Q q 1 0 0 1 62.69291 256.4236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 60 re B* Q q BT 1 0 0 1 0 38 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( Color['red']) Tj T* (<) Tj (Color.red: 1) Tj (>) Tj T* (>) Tj (>) Tj (>) Tj ( Color['green']) Tj T* (<) Tj (Color.green: 2) Tj (>) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 236.4236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (If have an enum member and need its ) Tj /F2 10 Tf (name) Tj /F1 10 Tf ( or ) Tj /F2 10 Tf (value) Tj /F1 10 Tf (:) Tj T* ET Q Q q 1 0 0 1 62.69291 155.2236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 72 re B* Q q BT 1 0 0 1 0 50 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( member = Color.red) Tj T* (>) Tj (>) Tj (>) Tj ( member.name) Tj T* ('red') Tj T* (>) Tj (>) Tj (>) Tj ( member.value) Tj T* (1) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 122.2236 cm q BT 1 0 0 1 0 3.5 Tm 21 TL /F3 17.5 Tf 0 0 0 rg (Duplicating enum members and values) Tj T* ET Q Q q 1 0 0 1 62.69291 92.22362 cm q 0 0 0 rg BT 1 0 0 1 0 14 Tm /F1 10 Tf 12 TL .13832 Tw (Having two enum members \(or any other attribute\) with the same name is invalid; in Python 3.x this would) Tj T* 0 Tw (raise an error, but in Python 2.x the second member simply overwrites the first:) Tj T* ET Q Q endstream endobj 92 0 obj << /Length 3296 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 571.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 192 re B* Q q BT 1 0 0 1 0 170 Tm 12 TL /F2 10 Tf 0 0 0 rg (# python 2.x) Tj T* (--) Tj (>) Tj ( class Shape\(Enum\):) Tj T* (... square = 2) Tj T* (... square = 3) Tj T* (...) Tj T* (--) Tj (>) Tj ( Shape.square) Tj T* (<) Tj (Shape.square: 3) Tj (>) Tj T* T* (# python 3.x) Tj T* (--) Tj (>) Tj ( class Shape\(Enum\):) Tj T* (... square = 2) Tj T* (... square = 3) Tj T* (Traceback \(most recent call last\):) Tj T* (...) Tj T* (TypeError: Attempted to reuse key: 'square') Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 527.8236 cm q 0 0 0 rg BT 1 0 0 1 0 26 Tm /F1 10 Tf 12 TL .384987 Tw (However, two enum members are allowed to have the same value. Given two members A and B with the) Tj T* 0 Tw .444772 Tw (same value \(and A defined first\), B is an alias to A. By-value lookup of the value of A and B will return A.) Tj T* 0 Tw (By-name lookup of B will also return A:) Tj T* ET Q Q q 1 0 0 1 62.69291 350.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 168 re B* Q q BT 1 0 0 1 0 146 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class Shape\(Enum\):) Tj T* (... _order_ = 'square diamond circle' # needed in 2.x) Tj T* (... square = 2) Tj T* (... diamond = 1) Tj T* (... circle = 3) Tj T* (... alias_for_square = 2) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( Shape.square) Tj T* (<) Tj (Shape.square: 2) Tj (>) Tj T* (>) Tj (>) Tj (>) Tj ( Shape.alias_for_square) Tj T* (<) Tj (Shape.square: 2) Tj (>) Tj T* (>) Tj (>) Tj (>) Tj ( Shape\(2\)) Tj T* (<) Tj (Shape.square: 2) Tj (>) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 318.6236 cm q BT 1 0 0 1 0 14 Tm 1.263516 Tw 12 TL /F1 10 Tf 0 0 0 rg (Allowing aliases is not always desirable. ) Tj /F2 10 Tf (unique) Tj /F1 10 Tf ( can be used to ensure that none exist in a particular) Tj T* 0 Tw (enumeration:) Tj T* ET Q Q q 1 0 0 1 62.69291 165.4236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 144 re B* Q q BT 1 0 0 1 0 122 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( from aenum import unique) Tj T* (>) Tj (>) Tj (>) Tj ( @unique) Tj T* (... class Mistake\(Enum\):) Tj T* (... _order_ = 'one two three' # only needed in 2.x) Tj T* (... one = 1) Tj T* (... two = 2) Tj T* (... three = 3) Tj T* (... four = 3) Tj T* (Traceback \(most recent call last\):) Tj T* (...) Tj T* (ValueError: duplicate names found in ) Tj (<) Tj (aenum 'Mistake') Tj (>) Tj (: four -) Tj (>) Tj ( three) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 145.4236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (Iterating over the members of an enum does not provide the aliases:) Tj T* ET Q Q q 1 0 0 1 62.69291 100.2236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 36 re B* Q q BT 1 0 0 1 0 14 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( list\(Shape\)) Tj T* ([) Tj (<) Tj (Shape.square: 2) Tj (>) Tj (, ) Tj (<) Tj (Shape.diamond: 1) Tj (>) Tj (, ) Tj (<) Tj (Shape.circle: 3) Tj (>) Tj (]) Tj T* ET Q Q Q Q Q endstream endobj 93 0 obj << /Length 4382 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 741.0236 cm q BT 1 0 0 1 0 14 Tm 1.537126 Tw 12 TL /F1 10 Tf 0 0 0 rg (The special attribute ) Tj /F2 10 Tf (__members__) Tj /F1 10 Tf ( is a dictionary mapping names to members. It includes all names) Tj T* 0 Tw (defined in the enumeration, including the aliases:) Tj T* ET Q Q q 1 0 0 1 62.69291 635.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 96 re B* Q q BT 1 0 0 1 0 74 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( for name, member in sorted\(Shape.__members__.items\(\)\):) Tj T* (... name, member) Tj T* (...) Tj T* (\('alias_for_square', ) Tj (<) Tj (Shape.square: 2) Tj (>) Tj (\)) Tj T* (\('circle', ) Tj (<) Tj (Shape.circle: 3) Tj (>) Tj (\)) Tj T* (\('diamond', ) Tj (<) Tj (Shape.diamond: 1) Tj (>) Tj (\)) Tj T* (\('square', ) Tj (<) Tj (Shape.square: 2) Tj (>) Tj (\)) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 603.8236 cm q BT 1 0 0 1 0 14 Tm .328443 Tw 12 TL /F1 10 Tf 0 0 0 rg (The ) Tj /F2 10 Tf (__members__) Tj /F1 10 Tf ( attribute can be used for detailed programmatic access to the enumeration members.) Tj T* 0 Tw (For example, finding all the aliases:) Tj T* ET Q Q q 1 0 0 1 62.69291 558.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 36 re B* Q q BT 1 0 0 1 0 14 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( [n for n, mbr in Shape.__members__.items\(\) if mbr.name != n]) Tj T* (['alias_for_square']) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 525.6236 cm q BT 1 0 0 1 0 3.5 Tm 21 TL /F3 17.5 Tf 0 0 0 rg (Comparisons) Tj T* ET Q Q q 1 0 0 1 62.69291 507.6236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (Enumeration members are compared by identity:) Tj T* ET Q Q q 1 0 0 1 62.69291 414.4236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 84 re B* Q q BT 1 0 0 1 0 62 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( Color.red is Color.red) Tj T* (True) Tj T* (>) Tj (>) Tj (>) Tj ( Color.red is Color.blue) Tj T* (False) Tj T* (>) Tj (>) Tj (>) Tj ( Color.red is not Color.blue) Tj T* (True) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 382.4236 cm q BT 1 0 0 1 0 14 Tm 1.131647 Tw 12 TL /F1 10 Tf 0 0 0 rg (Ordered comparisons between enumeration values are ) Tj /F5 10 Tf (not) Tj /F1 10 Tf ( supported. Enum members are not integers) Tj T* 0 Tw (\(but see ) Tj 0 0 .501961 rg (IntEnum) Tj 0 0 0 rg ( below\):) Tj T* ET Q Q q 1 0 0 1 62.69291 313.2236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 60 re B* Q q BT 1 0 0 1 0 38 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( Color.red ) Tj (<) Tj ( Color.blue) Tj T* (Traceback \(most recent call last\):) Tj T* ( File ") Tj (<) Tj (stdin) Tj (>) Tj (", line 1, in ) Tj (<) Tj (module) Tj (>) Tj T* (TypeError: unorderable types: Color\(\) ) Tj (<) Tj ( Color\(\)) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 293.2236 cm Q q 1 0 0 1 62.69291 210.2236 cm .960784 .960784 .862745 rg n 0 83 469.8898 -83 re f* 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 6 57 Tm T* ET q 1 0 0 1 16 52 cm q 0 0 0 rg BT 1 0 0 1 0 2.5 Tm /F4 12.5 Tf 15 TL (Warning) Tj T* ET Q Q q 1 0 0 1 16 16 cm q BT 1 0 0 1 0 14 Tm .189398 Tw 12 TL /F1 10 Tf 0 0 0 rg (In Python 2 ) Tj /F5 10 Tf (everything) Tj /F1 10 Tf ( is ordered, even though the ordering may not make sense. If you want your) Tj T* 0 Tw (enumerations to have a sensible ordering consider using an ) Tj 0 0 .501961 rg (OrderedEnum) Tj 0 0 0 rg (.) Tj T* ET Q Q q 1 J 1 j .662745 .662745 .662745 RG .5 w n 0 83 m 469.8898 83 l S n 0 0 m 469.8898 0 l S n 0 0 m 0 83 l S n 469.8898 0 m 469.8898 83 l S Q Q q 1 0 0 1 62.69291 204.2236 cm Q q 1 0 0 1 62.69291 186.2236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (Equality comparisons are defined though:) Tj T* ET Q Q q 1 0 0 1 62.69291 93.02362 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 84 re B* Q q BT 1 0 0 1 0 62 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( Color.blue == Color.red) Tj T* (False) Tj T* (>) Tj (>) Tj (>) Tj ( Color.blue != Color.red) Tj T* (True) Tj T* (>) Tj (>) Tj (>) Tj ( Color.blue == Color.blue) Tj T* (True) Tj T* ET Q Q Q Q Q endstream endobj 94 0 obj << /Length 4186 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 741.0236 cm q BT 1 0 0 1 0 14 Tm 2.875433 Tw 12 TL /F1 10 Tf 0 0 0 rg (Comparisons against non-enumeration values will always compare not equal \(again, ) Tj /F2 10 Tf (IntEnum) Tj /F1 10 Tf ( was) Tj T* 0 Tw (explicitly designed to behave differently, see below\):) Tj T* ET Q Q q 1 0 0 1 62.69291 695.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 36 re B* Q q BT 1 0 0 1 0 14 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( Color.blue == 2) Tj T* (False) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 662.8236 cm q BT 1 0 0 1 0 3.5 Tm 21 TL /F3 17.5 Tf 0 0 0 rg (Allowed members and attributes of enumerations) Tj T* ET Q Q q 1 0 0 1 62.69291 608.8236 cm q BT 1 0 0 1 0 38 Tm 2.755697 Tw 12 TL /F1 10 Tf 0 0 0 rg (The examples above use integers for enumeration values. Using integers is short and handy \(and) Tj T* 0 Tw 2.862485 Tw (provided by default by the ) Tj 0 0 .501961 rg (Enum Functional API) Tj 0 0 0 rg (\), but not strictly enforced. In the vast majority of) Tj T* 0 Tw 1.534692 Tw (use-cases, one doesn't care what the actual value of an enumeration is. But if the value ) Tj /F5 10 Tf (is) Tj /F1 10 Tf ( important,) Tj T* 0 Tw (enumerations can have arbitrary values.) Tj T* ET Q Q q 1 0 0 1 62.69291 578.8236 cm q 0 0 0 rg BT 1 0 0 1 0 14 Tm /F1 10 Tf 12 TL .638735 Tw (Enumerations are Python classes, and can have methods and special methods as usual. If we have this) Tj T* 0 Tw (enumeration:) Tj T* ET Q Q q 1 0 0 1 62.69291 377.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 192 re B* Q q BT 1 0 0 1 0 170 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class Mood\(Enum\):) Tj T* (... funky = 1) Tj T* (... happy = 3) Tj T* (...) Tj T* (... def describe\(self\):) Tj T* (... # self is the member here) Tj T* (... return self.name, self.value) Tj T* (...) Tj T* (... def __str__\(self\):) Tj T* (... return 'my custom str! {0}'.format\(self.value\)) Tj T* (...) Tj T* (... @classmethod) Tj T* (... def favorite_mood\(cls\):) Tj T* (... # cls here is the enumeration) Tj T* (... return cls.happy) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 357.6236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (Then:) Tj T* ET Q Q q 1 0 0 1 62.69291 264.4236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 84 re B* Q q BT 1 0 0 1 0 62 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( Mood.favorite_mood\(\)) Tj T* (<) Tj (Mood.happy: 3) Tj (>) Tj T* (>) Tj (>) Tj (>) Tj ( Mood.happy.describe\(\)) Tj T* (\('happy', 3\)) Tj T* (>) Tj (>) Tj (>) Tj ( str\(Mood.funky\)) Tj T* ('my custom str! 1') Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 208.4236 cm q BT 1 0 0 1 0 38 Tm 3.14186 Tw 12 TL /F1 10 Tf 0 0 0 rg (The rules for what is allowed are as follows: _sunder_ names \(starting and ending with a single) Tj T* 0 Tw .310651 Tw (underscore\) are reserved by enum and cannot be used; all other attributes defined within an enumeration) Tj T* 0 Tw 2.199213 Tw (will become members of this enumeration, with the exception of ) Tj /F5 10 Tf (__dunder__) Tj /F1 10 Tf ( names and descriptors) Tj T* 0 Tw (\(methods are also descriptors\).) Tj T* ET Q Q q 1 0 0 1 62.69291 196.4236 cm Q q 1 0 0 1 62.69291 113.4236 cm .960784 .960784 .862745 rg n 0 83 469.8898 -83 re f* 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 6 57 Tm T* ET q 1 0 0 1 16 52 cm q 0 0 0 rg BT 1 0 0 1 0 2.5 Tm /F4 12.5 Tf 15 TL (Note) Tj T* ET Q Q q 1 0 0 1 16 16 cm q BT 1 0 0 1 0 14 Tm .55152 Tw 12 TL /F1 10 Tf 0 0 0 rg (If your enumeration defines ) Tj /F2 10 Tf (__new__) Tj /F1 10 Tf ( and/or ) Tj /F2 10 Tf (__init__) Tj /F1 10 Tf ( then whatever value\(s\) were given to the) Tj T* 0 Tw (enum member will be passed into those methods. See ) Tj 0 0 .501961 rg (Planet) Tj 0 0 0 rg ( for an example.) Tj T* ET Q Q q 1 J 1 j .662745 .662745 .662745 RG .5 w n 0 83 m 469.8898 83 l S n 0 0 m 469.8898 0 l S n 0 0 m 0 83 l S n 469.8898 0 m 469.8898 83 l S Q Q q 1 0 0 1 62.69291 107.4236 cm Q endstream endobj 95 0 obj << /Length 4204 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 744.0236 cm q BT 1 0 0 1 0 3.5 Tm 21 TL /F3 17.5 Tf 0 0 0 rg (Restricted Enum subclassing) Tj T* ET Q Q q 1 0 0 1 62.69291 714.0236 cm q BT 1 0 0 1 0 14 Tm 2.512765 Tw 12 TL /F1 10 Tf 0 0 0 rg (A new ) Tj /F5 10 Tf (Enum) Tj /F1 10 Tf ( class must have one base Enum class, up to one concrete data type, and as many) Tj T* 0 Tw /F5 10 Tf (object) Tj /F1 10 Tf (-based mixin classes as needed. The order of these base classes is:) Tj T* ET Q Q q 1 0 0 1 62.69291 668.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 36 re B* Q q 0 0 0 rg BT 1 0 0 1 0 14 Tm /F2 10 Tf 12 TL (def EnumName\([mix-in, ...,] [data-type,] base-enum\):) Tj T* ( pass) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 648.8236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (Also, subclassing an enumeration is allowed only if the enumeration does not define) Tj T* ET Q Q q 1 0 0 1 62.69291 630.8236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (any members. So this is forbidden:) Tj T* ET Q Q q 1 0 0 1 62.69291 549.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 72 re B* Q q BT 1 0 0 1 0 50 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class MoreColor\(Color\):) Tj T* (... pink = 17) Tj T* (Traceback \(most recent call last\):) Tj T* (...) Tj T* (TypeError: ) Tj (<) Tj (aenum 'MoreColor') Tj (>) Tj ( cannot extend ) Tj (<) Tj (aenum 'Color') Tj (>) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 529.6236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (But this is allowed:) Tj T* ET Q Q q 1 0 0 1 62.69291 412.4236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 108 re B* Q q BT 1 0 0 1 0 86 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class Foo\(Enum\):) Tj T* (... def some_behavior\(self\):) Tj T* (... pass) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( class Bar\(Foo\):) Tj T* (... happy = 1) Tj T* (... sad = 2) Tj T* (...) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 368.4236 cm q BT 1 0 0 1 0 26 Tm .127984 Tw 12 TL /F1 10 Tf 0 0 0 rg (Allowing subclassing of enums that define members would lead to a violation of some important invariants) Tj T* 0 Tw 1.889985 Tw (of types and instances. On the other hand, it makes sense to allow sharing some common behavior) Tj T* 0 Tw (between a group of enumerations. \(See ) Tj 0 0 .501961 rg (OrderedEnum) Tj 0 0 0 rg ( for an example.\)) Tj T* ET Q Q q 1 0 0 1 62.69291 335.4236 cm q BT 1 0 0 1 0 3.5 Tm 21 TL /F3 17.5 Tf 0 0 0 rg (Pickling) Tj T* ET Q Q q 1 0 0 1 62.69291 317.4236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (Enumerations can be pickled and unpickled:) Tj T* ET Q Q q 1 0 0 1 62.69291 248.2236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 60 re B* Q q BT 1 0 0 1 0 38 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( from aenum.test import Fruit) Tj T* (>) Tj (>) Tj (>) Tj ( from pickle import dumps, loads) Tj T* (>) Tj (>) Tj (>) Tj ( Fruit.tomato is loads\(dumps\(Fruit.tomato, 2\)\)) Tj T* (True) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 216.2236 cm q 0 0 0 rg BT 1 0 0 1 0 14 Tm /F1 10 Tf 12 TL 1.256457 Tw (The usual restrictions for pickling apply: picklable enums must be defined in the top level of a module,) Tj T* 0 Tw (since unpickling requires them to be importable from that module.) Tj T* ET Q Q q 1 0 0 1 62.69291 204.2236 cm Q q 1 0 0 1 62.69291 121.2236 cm .960784 .960784 .862745 rg n 0 83 469.8898 -83 re f* 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 6 57 Tm T* ET q 1 0 0 1 16 52 cm q 0 0 0 rg BT 1 0 0 1 0 2.5 Tm /F4 12.5 Tf 15 TL (Note) Tj T* ET Q Q q 1 0 0 1 16 16 cm q 0 0 0 rg BT 1 0 0 1 0 14 Tm /F1 10 Tf 12 TL -0.003765 Tw (With pickle protocol version 4 \(introduced in Python 3.4\) it is possible to easily pickle enums nested) Tj T* 0 Tw (in other classes.) Tj T* ET Q Q q 1 J 1 j .662745 .662745 .662745 RG .5 w n 0 83 m 469.8898 83 l S n 0 0 m 469.8898 0 l S n 0 0 m 0 83 l S n 469.8898 0 m 469.8898 83 l S Q Q q 1 0 0 1 62.69291 115.2236 cm Q endstream endobj 96 0 obj << /Length 4534 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 744.0236 cm q BT 1 0 0 1 0 3.5 Tm 21 TL /F3 17.5 Tf 0 0 0 rg (Enum Functional API) Tj T* ET Q Q q 1 0 0 1 62.69291 726.0236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (The ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( class is callable, providing the following functional API:) Tj T* ET Q Q q 1 0 0 1 62.69291 596.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 120 re B* Q q BT 1 0 0 1 0 98 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( Animal = Enum\('Animal', 'ant bee cat dog'\)) Tj T* (>) Tj (>) Tj (>) Tj ( Animal) Tj T* (<) Tj (aenum 'Animal') Tj (>) Tj T* (>) Tj (>) Tj (>) Tj ( Animal.ant) Tj T* (<) Tj (Animal.ant: 1) Tj (>) Tj T* (>) Tj (>) Tj (>) Tj ( Animal.ant.value) Tj T* (1) Tj T* (>) Tj (>) Tj (>) Tj ( list\(Animal\)) Tj T* ([) Tj (<) Tj (Animal.ant: 1) Tj (>) Tj (, ) Tj (<) Tj (Animal.bee: 2) Tj (>) Tj (, ) Tj (<) Tj (Animal.cat: 3) Tj (>) Tj (, ) Tj (<) Tj (Animal.dog: 4) Tj (>) Tj (]) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 564.8236 cm q BT 1 0 0 1 0 14 Tm .781098 Tw 12 TL /F1 10 Tf 0 0 0 rg (The semantics of this API resemble ) Tj /F2 10 Tf (namedtuple) Tj /F1 10 Tf (. The first argument of the call to ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( is the name of) Tj T* 0 Tw (the enumeration.) Tj T* ET Q Q q 1 0 0 1 62.69291 498.8236 cm q BT 1 0 0 1 0 50 Tm 1.326412 Tw 12 TL /F1 10 Tf 0 0 0 rg (The second argument is the ) Tj /F5 10 Tf (source) Tj /F1 10 Tf ( of enumeration member names. It can be a whitespace-separated) Tj T* 0 Tw .993516 Tw (string of names, a sequence of names, a sequence of 2-tuples with key/value pairs, or a mapping \(e.g.) Tj T* 0 Tw -0.021349 Tw (dictionary\) of names to values. The last two options enable assigning arbitrary values to enumerations; the) Tj T* 0 Tw .18311 Tw (others auto-assign increasing integers starting with 1. A new class derived from ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( is returned. In other) Tj T* 0 Tw (words, the above assignment to ) Tj /F2 10 Tf (Animal) Tj /F1 10 Tf ( is equivalent to:) Tj T* ET Q Q q 1 0 0 1 62.69291 417.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 72 re B* Q q BT 1 0 0 1 0 50 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class Animals\(Enum\):) Tj T* (... ant = 1) Tj T* (... bee = 2) Tj T* (... cat = 3) Tj T* (... dog = 4) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 361.6236 cm q 0 0 0 rg BT 1 0 0 1 0 38 Tm /F1 10 Tf 12 TL 1.239984 Tw (Pickling enums created with the functional API can be tricky as frame stack implementation details are) Tj T* 0 Tw .937132 Tw (used to try and figure out which module the enumeration is being created in \(e.g. it will fail if you use a) Tj T* 0 Tw 1.321163 Tw (utility function in separate module, and also may not work on IronPython or Jython\). The solution is to) Tj T* 0 Tw (specify the module name explicitly as follows:) Tj T* ET Q Q q 1 0 0 1 62.69291 328.4236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 24 re B* Q q BT 1 0 0 1 0 2 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( Animals = Enum\('Animals', 'ant bee cat dog', module=__name__\)) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 295.4236 cm q BT 1 0 0 1 0 3.5 Tm 21 TL /F3 17.5 Tf 0 0 0 rg (Derived Enumerations) Tj T* ET Q Q q 1 0 0 1 62.69291 265.4236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (IntEnum) Tj T* ET Q Q q 1 0 0 1 62.69291 223.4236 cm q BT 1 0 0 1 0 26 Tm 2.356098 Tw 12 TL /F1 10 Tf 0 0 0 rg (A variation of ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( is provided which is also a subclass of ) Tj /F2 10 Tf (int) Tj /F1 10 Tf (. Members of an ) Tj /F2 10 Tf (IntEnum) Tj /F1 10 Tf ( can be) Tj T* 0 Tw .087984 Tw (compared to integers; by extension, integer enumerations of different types can also be compared to each) Tj T* 0 Tw (other:) Tj T* ET Q Q q 1 0 0 1 62.69291 82.22362 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 132 re B* Q q BT 1 0 0 1 0 110 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( from aenum import IntEnum) Tj T* (>) Tj (>) Tj (>) Tj ( class Shape\(IntEnum\):) Tj T* (... circle = 1) Tj T* (... square = 2) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( class Request\(IntEnum\):) Tj T* (... post = 1) Tj T* (... get = 2) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( Shape == 1) Tj T* ET Q Q Q Q Q endstream endobj 97 0 obj << /Length 4155 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 691.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 72 re B* Q q BT 1 0 0 1 0 50 Tm 12 TL /F2 10 Tf 0 0 0 rg (False) Tj T* (>) Tj (>) Tj (>) Tj ( Shape.circle == 1) Tj T* (True) Tj T* (>) Tj (>) Tj (>) Tj ( Shape.circle == Request.post) Tj T* (True) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 671.8236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (However, they still can't be compared to standard ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( enumerations:) Tj T* ET Q Q q 1 0 0 1 62.69291 530.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 132 re B* Q q BT 1 0 0 1 0 110 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class Shape\(IntEnum\):) Tj T* (... circle = 1) Tj T* (... square = 2) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( class Color\(Enum\):) Tj T* (... red = 1) Tj T* (... green = 2) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( Shape.circle == Color.red) Tj T* (False) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 510.6236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F2 10 Tf 0 0 0 rg (IntEnum) Tj /F1 10 Tf ( values behave like integers in other ways you'd expect:) Tj T* ET Q Q q 1 0 0 1 62.69291 417.4236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 84 re B* Q q BT 1 0 0 1 0 62 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( int\(Shape.circle\)) Tj T* (1) Tj T* (>) Tj (>) Tj (>) Tj ( ['a', 'b', 'c'][Shape.circle]) Tj T* ('b') Tj T* (>) Tj (>) Tj (>) Tj ( [i for i in range\(Shape.square\)]) Tj T* ([0, 1]) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 349.4236 cm q BT 1 0 0 1 0 50 Tm 1.657126 Tw 12 TL /F1 10 Tf 0 0 0 rg (For the vast majority of code, ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( is strongly recommended, since ) Tj /F2 10 Tf (IntEnum) Tj /F1 10 Tf ( breaks some semantic) Tj T* 0 Tw .793318 Tw (promises of an enumeration \(by being comparable to integers, and thus by transitivity to other unrelated) Tj T* 0 Tw .554985 Tw (enumerations\). It should be used only in special cases where there's no other choice; for example, when) Tj T* 0 Tw .746136 Tw (integer constants are replaced with enumerations and backwards compatibility is required with code that) Tj T* 0 Tw (still expects integers.) Tj T* ET Q Q q 1 0 0 1 62.69291 319.4236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (IntFlag) Tj T* ET Q Q q 1 0 0 1 62.69291 253.4236 cm q BT 1 0 0 1 0 50 Tm 1.581318 Tw 12 TL /F1 10 Tf 0 0 0 rg (The next variation of ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( provided, ) Tj /F2 10 Tf (IntFlag) Tj /F1 10 Tf (, is also based on ) Tj /F2 10 Tf (int) Tj /F1 10 Tf (. The difference being ) Tj /F2 10 Tf (IntFlag) Tj /F1 10 Tf T* 0 Tw 1.798876 Tw (members can be combined using the bitwise operators \() Tj (&) Tj (, |, ^, ~\) and the result is still an ) Tj /F2 10 Tf (IntFlag) Tj /F1 10 Tf T* 0 Tw 2.958555 Tw (member. However, as the name implies, ) Tj /F2 10 Tf (IntFlag) Tj /F1 10 Tf ( members also subclass ) Tj /F2 10 Tf (int) Tj /F1 10 Tf ( and can be used) Tj T* 0 Tw .156235 Tw (wherever an ) Tj /F2 10 Tf (int) Tj /F1 10 Tf ( is used. Any operation on an ) Tj /F2 10 Tf (IntFlag) Tj /F1 10 Tf ( member besides the bit-wise operations will lose) Tj T* 0 Tw (the ) Tj /F2 10 Tf (IntFlag) Tj /F1 10 Tf ( membership.) Tj T* ET Q Q q 1 0 0 1 62.69291 235.4236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (Sample ) Tj /F2 10 Tf (IntFlag) Tj /F1 10 Tf ( class:) Tj T* ET Q Q q 1 0 0 1 62.69291 82.22362 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 144 re B* Q q BT 1 0 0 1 0 122 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( from aenum import IntFlag) Tj T* (>) Tj (>) Tj (>) Tj ( class Perm\(IntFlag\):) Tj T* (... _order_ = 'R W X') Tj T* (... R = 4) Tj T* (... W = 2) Tj T* (... X = 1) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( Perm.R | Perm.W) Tj T* (<) Tj (Perm.R|W: 6) Tj (>) Tj T* (>) Tj (>) Tj (>) Tj ( Perm.R + Perm.W) Tj T* (6) Tj T* ET Q Q Q Q Q endstream endobj 98 0 obj << /Length 4053 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 715.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 48 re B* Q q BT 1 0 0 1 0 26 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( RW = Perm.R | Perm.W) Tj T* (>) Tj (>) Tj (>) Tj ( Perm.R in RW) Tj T* (True) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 695.8236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (It is also possible to name the combinations:) Tj T* ET Q Q q 1 0 0 1 62.69291 554.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 132 re B* Q q BT 1 0 0 1 0 110 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class Perm\(IntFlag\):) Tj T* (... _order_ = 'R W X') Tj T* (... R = 4) Tj T* (... W = 2) Tj T* (... X = 1) Tj T* (... RWX = 7) Tj T* (>) Tj (>) Tj (>) Tj ( Perm.RWX) Tj T* (<) Tj (Perm.RWX: 7) Tj (>) Tj T* (>) Tj (>) Tj (>) Tj ( ~Perm.RWX) Tj T* (<) Tj (Perm: 0) Tj (>) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 522.6236 cm q BT 1 0 0 1 0 14 Tm 1.100542 Tw 12 TL /F1 10 Tf 0 0 0 rg (Another important difference between ) Tj /F2 10 Tf (IntFlag) Tj /F1 10 Tf ( and ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( is that if no flags are set \(the value is 0\), its) Tj T* 0 Tw (boolean evaluation is ) Tj /F2 10 Tf (False) Tj /F1 10 Tf (:) Tj T* ET Q Q q 1 0 0 1 62.69291 453.4236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 60 re B* Q q BT 1 0 0 1 0 38 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( Perm.R ) Tj (&) Tj ( Perm.X) Tj T* (<) Tj (Perm: 0) Tj (>) Tj T* (>) Tj (>) Tj (>) Tj ( bool\(Perm.R ) Tj (&) Tj ( Perm.X\)) Tj T* (False) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 433.4236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (Because ) Tj /F2 10 Tf (IntFlag) Tj /F1 10 Tf ( members are also subclasses of ) Tj /F2 10 Tf (int) Tj /F1 10 Tf ( they can be combined with them:) Tj T* ET Q Q q 1 0 0 1 62.69291 388.2236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 36 re B* Q q BT 1 0 0 1 0 14 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( Perm.X | 4) Tj T* (<) Tj (Perm.R|X: 5) Tj (>) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 356.2236 cm q BT 1 0 0 1 0 14 Tm .472339 Tw 12 TL /F1 10 Tf 0 0 0 rg (If the result is not a ) Tj /F2 10 Tf (Flag) Tj /F1 10 Tf ( then, depending on the ) Tj /F2 10 Tf (_boundary_) Tj /F1 10 Tf ( setting, an exception is raised \() Tj /F2 10 Tf (STRICT) Tj /F1 10 Tf (\),) Tj T* 0 Tw (the extra bits are lost \() Tj /F2 10 Tf (CONFORM) Tj /F1 10 Tf (\), or it reverts to an int \() Tj /F2 10 Tf (EJECT) Tj /F1 10 Tf (\):) Tj T* ET Q Q q 1 0 0 1 62.69291 350.2236 cm Q q 1 0 0 1 62.69291 134.6236 cm 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 0 2 Tm T* ET q 1 0 0 1 20 130.4 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 448.6898 84 re B* Q q BT 1 0 0 1 0 62 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( from aenum import STRICT, CONFORM, EJECT) Tj T* (>) Tj (>) Tj (>) Tj ( Perm._boundary_ = STRICT) Tj T* (>) Tj (>) Tj (>) Tj ( Perm.X | 8) Tj T* (Traceback \(most recent call last\):) Tj T* (...) Tj T* (ValueError: 9 is not a valid Perm) Tj T* ET Q Q Q Q Q q 1 0 0 1 20 65.2 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 448.6898 48 re B* Q q BT 1 0 0 1 0 26 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( Perm._boundary_ = EJECT) Tj T* (>) Tj (>) Tj (>) Tj ( Perm.X | 8) Tj T* (9) Tj T* ET Q Q Q Q Q q 1 0 0 1 20 0 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 448.6898 48 re B* Q q BT 1 0 0 1 0 26 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( Perm._boundary_ = CONFORM) Tj T* (>) Tj (>) Tj (>) Tj ( Perm.X | 8) Tj T* (<) Tj (Perm.X: 1) Tj (>) Tj T* ET Q Q Q Q Q q Q Q q 1 0 0 1 62.69291 134.6236 cm Q endstream endobj 99 0 obj << /Length 3958 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 747.0236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (Flag) Tj T* ET Q Q q 1 0 0 1 62.69291 693.0236 cm q BT 1 0 0 1 0 38 Tm -0.12064 Tw 12 TL /F1 10 Tf 0 0 0 rg (The last variation is ) Tj /F2 10 Tf (Flag) Tj /F1 10 Tf (. Like ) Tj /F2 10 Tf (IntFlag) Tj /F1 10 Tf (, ) Tj /F2 10 Tf (Flag) Tj /F1 10 Tf ( members can be combined using the bitwise operators \() Tj (&) Tj (,) Tj T* 0 Tw 3.335984 Tw (|, ^, ~\). Unlike ) Tj /F2 10 Tf (IntFlag) Tj /F1 10 Tf (, they cannot be combined with, nor compared against, any other ) Tj /F2 10 Tf (Flag) Tj /F1 10 Tf T* 0 Tw .182209 Tw (enumeration, nor ) Tj /F2 10 Tf (int) Tj /F1 10 Tf (. While it is possible to specify the values directly it is recommended to use ) Tj /F2 10 Tf (auto) Tj /F1 10 Tf ( as) Tj T* 0 Tw (the value and let ) Tj /F2 10 Tf (Flag) Tj /F1 10 Tf ( select an appropriate value.) Tj T* ET Q Q q 1 0 0 1 62.69291 663.0236 cm q BT 1 0 0 1 0 14 Tm .511751 Tw 12 TL /F1 10 Tf 0 0 0 rg (Like ) Tj /F2 10 Tf (IntFlag) Tj /F1 10 Tf (, if a combination of ) Tj /F2 10 Tf (Flag) Tj /F1 10 Tf ( members results in no flags being set, the boolean evaluation is) Tj T* 0 Tw /F2 10 Tf (False) Tj /F1 10 Tf (:) Tj T* ET Q Q q 1 0 0 1 62.69291 521.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 132 re B* Q q BT 1 0 0 1 0 110 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( from aenum import Flag, auto) Tj T* (>) Tj (>) Tj (>) Tj ( class Color\(Flag\):) Tj T* (... RED = auto\(\)) Tj T* (... BLUE = auto\(\)) Tj T* (... GREEN = auto\(\)) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( Color.RED ) Tj (&) Tj ( Color.GREEN) Tj T* (<) Tj (Color: 0) Tj (>) Tj T* (>) Tj (>) Tj (>) Tj ( bool\(Color.RED ) Tj (&) Tj ( Color.GREEN\)) Tj T* (False) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 501.8236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (Individual flags should have values that are powers of two \(1, 2, 4, 8, ...\), while combinations of flags won't:) Tj T* ET Q Q q 1 0 0 1 62.69291 384.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 108 re B* Q q BT 1 0 0 1 0 86 Tm 12 TL /F2 10 Tf 0 0 0 rg (--) Tj (>) Tj ( class Color\(Flag\):) Tj T* (... RED = auto\(\)) Tj T* (... BLUE = auto\(\)) Tj T* (... GREEN = auto\(\)) Tj T* (... WHITE = RED | BLUE | GREEN) Tj T* (...) Tj T* (--) Tj (>) Tj ( Color.WHITE) Tj T* (<) Tj (Color.WHITE: 7) Tj (>) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 364.6236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (Giving a name to the "no flags set" condition does not change its boolean value:) Tj T* ET Q Q q 1 0 0 1 62.69291 223.4236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 132 re B* Q q BT 1 0 0 1 0 110 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class Color\(Flag\):) Tj T* (... BLACK = 0) Tj T* (... RED = auto\(\)) Tj T* (... BLUE = auto\(\)) Tj T* (... GREEN = auto\(\)) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( Color.BLACK) Tj T* (<) Tj (Color.BLACK: 0) Tj (>) Tj T* (>) Tj (>) Tj (>) Tj ( bool\(Color.BLACK\)) Tj T* (False) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 203.4236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (Flags can be iterated over to retrieve the individual truthy flags in the value:) Tj T* ET Q Q q 1 0 0 1 62.69291 86.22362 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 108 re B* Q q BT 1 0 0 1 0 86 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class Color\(Flag\):) Tj T* (... _order_ = 'BLACK RED BLUE GREEN WHITE') Tj T* (... BLACK = 0) Tj T* (... RED = auto\(\)) Tj T* (... BLUE = auto\(\)) Tj T* (... GREEN = auto\(\)) Tj T* (... WHITE = RED | BLUE | GREEN) Tj T* (...) Tj T* ET Q Q Q Q Q endstream endobj 100 0 obj << /Length 6807 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 703.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 60 re B* Q q BT 1 0 0 1 0 38 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( list\(Color.GREEN\)) Tj T* ([) Tj (<) Tj (Color.GREEN: 4) Tj (>) Tj (]) Tj T* (>) Tj (>) Tj (>) Tj ( list\(Color.WHITE\)) Tj T* ([) Tj (<) Tj (Color.RED: 1) Tj (>) Tj (, ) Tj (<) Tj (Color.BLUE: 2) Tj (>) Tj (, ) Tj (<) Tj (Color.GREEN: 4) Tj (>) Tj (]) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 683.8236 cm Q q 1 0 0 1 62.69291 564.8236 cm .960784 .960784 .862745 rg n 0 119 469.8898 -119 re f* 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 6 93 Tm T* ET q 1 0 0 1 16 88 cm q 0 0 0 rg BT 1 0 0 1 0 2.5 Tm /F4 12.5 Tf 15 TL (Note) Tj T* ET Q Q q 1 0 0 1 16 16 cm q BT 1 0 0 1 0 50 Tm 1.505697 Tw 12 TL /F1 10 Tf 0 0 0 rg (For the majority of new code, ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( and ) Tj /F2 10 Tf (Flag) Tj /F1 10 Tf ( are strongly recommended, since ) Tj /F2 10 Tf (IntEnum) Tj /F1 10 Tf ( and) Tj T* 0 Tw .055366 Tw /F2 10 Tf (IntFlag) Tj /F1 10 Tf ( break some semantic promises of an enumeration \(by being comparable to integers, and) Tj T* 0 Tw .54229 Tw (thus by transitivity to other unrelated enumerations\). ) Tj /F2 10 Tf (IntEnum) Tj /F1 10 Tf ( and ) Tj /F2 10 Tf (IntFlag) Tj /F1 10 Tf ( should be used only) Tj T* 0 Tw .36436 Tw (in cases where ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( and ) Tj /F2 10 Tf (Flag) Tj /F1 10 Tf ( will not do; for example, when integer constants are replaced with) Tj T* 0 Tw (enumerations, or for interoperability with other systems.) Tj T* ET Q Q q 1 J 1 j .662745 .662745 .662745 RG .5 w n 0 119 m 469.8898 119 l S n 0 0 m 469.8898 0 l S n 0 0 m 0 119 l S n 469.8898 0 m 469.8898 119 l S Q Q q 1 0 0 1 62.69291 558.8236 cm Q q 1 0 0 1 62.69291 528.8236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (Others) Tj T* ET Q Q q 1 0 0 1 62.69291 510.8236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (While ) Tj /F2 10 Tf (IntEnum) Tj /F1 10 Tf ( is part of the ) Tj /F2 10 Tf (aenum) Tj /F1 10 Tf ( module, it would be very simple to implement independently:) Tj T* ET Q Q q 1 0 0 1 62.69291 465.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 36 re B* Q q 0 0 0 rg BT 1 0 0 1 0 14 Tm /F2 10 Tf 12 TL (class MyIntEnum\(int, Enum\):) Tj T* ( pass) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 433.6236 cm q BT 1 0 0 1 0 14 Tm 1.936136 Tw 12 TL /F1 10 Tf 0 0 0 rg (This demonstrates how similar derived enumerations can be defined; for example a ) Tj /F2 10 Tf (MyStrEnum) Tj /F1 10 Tf ( that) Tj T* 0 Tw (mixes in ) Tj /F2 10 Tf (str) Tj /F1 10 Tf ( instead of ) Tj /F2 10 Tf (int) Tj /F1 10 Tf (.) Tj T* ET Q Q q 1 0 0 1 62.69291 415.6236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (Some rules:) Tj T* ET Q Q q 1 0 0 1 62.69291 409.6236 cm Q q 1 0 0 1 62.69291 409.6236 cm Q q 1 0 0 1 62.69291 385.6236 cm 0 0 0 rg BT /F1 10 Tf 12 TL ET q 1 0 0 1 6 9 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL 5.66 0 Td (1.) Tj T* -5.66 0 Td ET Q Q q 1 0 0 1 23 -3 cm q BT 1 0 0 1 0 14 Tm -0.011265 Tw 12 TL /F1 10 Tf 0 0 0 rg (When subclassing ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf (, mix-in types must appear before ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( itself in the sequence of bases, as in) Tj T* 0 Tw (the ) Tj /F2 10 Tf (MyIntEnum) Tj /F1 10 Tf ( example above.) Tj T* ET Q Q q Q Q q 1 0 0 1 62.69291 379.6236 cm Q q 1 0 0 1 62.69291 343.6236 cm 0 0 0 rg BT /F1 10 Tf 12 TL ET q 1 0 0 1 6 21 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL 5.66 0 Td (2.) Tj T* -5.66 0 Td ET Q Q q 1 0 0 1 23 -3 cm q BT 1 0 0 1 0 26 Tm -0.096124 Tw 12 TL /F1 10 Tf 0 0 0 rg (While ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( can have members of any type, once you mix in an additional type, all the members must) Tj T* 0 Tw 1.210574 Tw (have values of that type or be convertible into that type. This restriction does not apply to mix-ins) Tj T* 0 Tw (which only add methods and don't specify another data type.) Tj T* ET Q Q q Q Q q 1 0 0 1 62.69291 337.6236 cm Q q 1 0 0 1 62.69291 313.6236 cm 0 0 0 rg BT /F1 10 Tf 12 TL ET q 1 0 0 1 6 9 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL 5.66 0 Td (3.) Tj T* -5.66 0 Td ET Q Q q 1 0 0 1 23 -3 cm q BT 1 0 0 1 0 14 Tm .279431 Tw 12 TL /F1 10 Tf 0 0 0 rg (When another data type is mixed in, the ) Tj /F2 10 Tf (value) Tj /F1 10 Tf ( attribute is ) Tj /F5 10 Tf (not the same) Tj /F1 10 Tf ( as the enum member itself,) Tj T* 0 Tw (although it is equivalant and will compare equal.) Tj T* ET Q Q q Q Q q 1 0 0 1 62.69291 307.6236 cm Q q 1 0 0 1 62.69291 283.6236 cm 0 0 0 rg BT /F1 10 Tf 12 TL ET q 1 0 0 1 6 9 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL 5.66 0 Td (4.) Tj T* -5.66 0 Td ET Q Q q 1 0 0 1 23 -3 cm q BT 1 0 0 1 0 14 Tm .613059 Tw 12 TL /F1 10 Tf 0 0 0 rg (%-style formatting: ) Tj /F2 10 Tf (%s) Tj /F1 10 Tf ( and ) Tj /F2 10 Tf (%r) Tj /F1 10 Tf ( call ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ('s ) Tj /F2 10 Tf (__str__) Tj /F1 10 Tf ( and ) Tj /F2 10 Tf (__repr__) Tj /F1 10 Tf ( respectively; other codes \(such) Tj T* 0 Tw (as ) Tj /F2 10 Tf (%i) Tj /F1 10 Tf ( or ) Tj /F2 10 Tf (%h) Tj /F1 10 Tf ( for MyIntEnum\) treat the enum member as its mixed-in type.) Tj T* ET Q Q q Q Q q 1 0 0 1 62.69291 277.6236 cm Q q 1 0 0 1 62.69291 253.6236 cm 0 0 0 rg BT /F1 10 Tf 12 TL ET q 1 0 0 1 6 9 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL 5.66 0 Td (5.) Tj T* -5.66 0 Td ET Q Q q 1 0 0 1 23 -3 cm q BT 1 0 0 1 0 14 Tm .063555 Tw 12 TL /F2 10 Tf 0 0 0 rg (str.__format__) Tj /F1 10 Tf ( \(or ) Tj /F2 10 Tf (format) Tj /F1 10 Tf (\) will use the mixed-in type's ) Tj /F2 10 Tf (__format__) Tj /F1 10 Tf (. If the ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ('s ) Tj /F2 10 Tf (str) Tj /F1 10 Tf ( or ) Tj /F2 10 Tf (repr) Tj /F1 10 Tf T* 0 Tw (is desired use the ) Tj /F2 10 Tf (!s) Tj /F1 10 Tf ( or ) Tj /F2 10 Tf (!r) Tj /F1 10 Tf ( ) Tj /F2 10 Tf (str) Tj /F1 10 Tf ( format codes.) Tj T* ET Q Q q Q Q q 1 0 0 1 62.69291 253.6236 cm Q q 1 0 0 1 62.69291 241.6236 cm Q q 1 0 0 1 62.69291 158.6236 cm .960784 .960784 .862745 rg n 0 83 469.8898 -83 re f* 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 6 57 Tm T* ET q 1 0 0 1 16 52 cm q 0 0 0 rg BT 1 0 0 1 0 2.5 Tm /F4 12.5 Tf 15 TL (Note) Tj T* ET Q Q q 1 0 0 1 16 16 cm q BT 1 0 0 1 0 14 Tm 2.198221 Tw 12 TL /F1 10 Tf 0 0 0 rg (If you override the ) Tj /F2 10 Tf (__str__) Tj /F1 10 Tf ( method, then it will be used to provide the string portion of the) Tj T* 0 Tw /F2 10 Tf (format\(\)) Tj /F1 10 Tf ( call.) Tj T* ET Q Q q 1 J 1 j .662745 .662745 .662745 RG .5 w n 0 83 m 469.8898 83 l S n 0 0 m 469.8898 0 l S n 0 0 m 0 83 l S n 469.8898 0 m 469.8898 83 l S Q Q q 1 0 0 1 62.69291 152.6236 cm Q q 1 0 0 1 62.69291 140.6236 cm Q endstream endobj 101 0 obj << /Length 4047 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 682.0236 cm .960784 .960784 .862745 rg n 0 83 469.8898 -83 re f* 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 6 57 Tm T* ET q 1 0 0 1 16 52 cm q 0 0 0 rg BT 1 0 0 1 0 2.5 Tm /F4 12.5 Tf 15 TL (Note) Tj T* ET Q Q q 1 0 0 1 16 16 cm q BT 1 0 0 1 0 14 Tm .151751 Tw 12 TL /F1 10 Tf 0 0 0 rg (Prior to Python 3.4 there is a bug in ) Tj /F2 10 Tf (str) Tj /F1 10 Tf ('s %-formatting: ) Tj /F2 10 Tf (int) Tj /F1 10 Tf ( subclasses are printed as strings and) Tj T* 0 Tw (not numbers when the ) Tj /F2 10 Tf (%d) Tj /F1 10 Tf (, ) Tj /F2 10 Tf (%i) Tj /F1 10 Tf (, or ) Tj /F2 10 Tf (%u) Tj /F1 10 Tf ( codes are used.) Tj T* ET Q Q q 1 J 1 j .662745 .662745 .662745 RG .5 w n 0 83 m 469.8898 83 l S n 0 0 m 469.8898 0 l S n 0 0 m 0 83 l S n 469.8898 0 m 469.8898 83 l S Q Q q 1 0 0 1 62.69291 676.0236 cm Q q 1 0 0 1 62.69291 643.0236 cm q BT 1 0 0 1 0 3.5 Tm 21 TL /F3 17.5 Tf 0 0 0 rg (Extra Goodies) Tj T* ET Q Q q 1 0 0 1 62.69291 625.0236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (aenum supports a few extra techniques not found in the stdlib version.) Tj T* ET Q Q q 1 0 0 1 62.69291 595.0236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (enum) Tj T* ET Q Q q 1 0 0 1 62.69291 565.0236 cm q BT 1 0 0 1 0 14 Tm .402339 Tw 12 TL /F1 10 Tf 0 0 0 rg (If you have several items to initialize your ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( members with and would like to use keyword arguments,) Tj T* 0 Tw (the ) Tj /F2 10 Tf (enum) Tj /F1 10 Tf ( helper is for you:) Tj T* ET Q Q q 1 0 0 1 62.69291 447.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 108 re B* Q q BT 1 0 0 1 0 86 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( from aenum import enum) Tj T* (>) Tj (>) Tj (>) Tj ( class Presidents\(Enum\):) Tj T* (... Washington = enum\('George Washington', circa=1776, death=1797\)) Tj T* (... Jackson = enum\('Andrew Jackson', circa=1830, death=1837\)) Tj T* (... Lincoln = enum\('Abraham Lincoln', circa=1860, death=1865\)) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( Presidents.Lincoln) Tj T* (<) Tj (Presidents.Lincoln: enum\('Abraham Lincoln', circa=1860, death=1865\)) Tj (>) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 417.8236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (extend_enum) Tj T* ET Q Q q 1 0 0 1 62.69291 387.8236 cm q BT 1 0 0 1 0 14 Tm .87832 Tw 12 TL /F1 10 Tf 0 0 0 rg (For those rare cases when you need to create your ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( in pieces, you can use ) Tj /F2 10 Tf (extend_enum) Tj /F1 10 Tf ( to add) Tj T* 0 Tw (new members after the initial creation \(the new member is returned\):) Tj T* ET Q Q q 1 0 0 1 62.69291 78.62362 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 300 re B* Q q BT 1 0 0 1 0 278 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( from aenum import extend_enum) Tj T* (>) Tj (>) Tj (>) Tj ( class Color\(Enum\):) Tj T* (... red = 1) Tj T* (... green = 2) Tj T* (... blue = 3) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( list\(Color\)) Tj T* ([) Tj (<) Tj (Color.red: 1) Tj (>) Tj (, ) Tj (<) Tj (Color.green: 2) Tj (>) Tj (, ) Tj (<) Tj (Color.blue: 3) Tj (>) Tj (]) Tj T* (>) Tj (>) Tj (>) Tj ( extend_enum\(Color, 'opacity', 4\)) Tj T* (<) Tj (Color.opacity: 4) Tj (>) Tj T* (>) Tj (>) Tj (>) Tj ( list\(Color\)) Tj T* ([) Tj (<) Tj (Color.red: 1) Tj (>) Tj (, ) Tj (<) Tj (Color.green: 2) Tj (>) Tj (, ) Tj (<) Tj (Color.blue: 3) Tj (>) Tj (, ) Tj (<) Tj (Color.opacity: 4) Tj (>) Tj (]) Tj T* (>) Tj (>) Tj (>) Tj ( Color.opacity in Color) Tj T* (True) Tj T* (>) Tj (>) Tj (>) Tj ( Color.opacity.name == 'opacity') Tj T* (True) Tj T* (>) Tj (>) Tj (>) Tj ( Color.opacity.value == 4) Tj T* (True) Tj T* (>) Tj (>) Tj (>) Tj ( Color\(4\)) Tj T* (<) Tj (Color.opacity: 4) Tj (>) Tj T* (>) Tj (>) Tj (>) Tj ( Color['opacity']) Tj T* (<) Tj (Color.opacity: 4) Tj (>) Tj T* T* (--) Tj (>) Tj ( Color.__members__) Tj T* ET Q Q Q Q Q endstream endobj 102 0 obj << /Length 3217 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 679.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 84 re B* Q q BT 1 0 0 1 0 62 Tm 12 TL /F2 10 Tf 0 0 0 rg (OrderedDict\([) Tj T* ( \('red', ) Tj (<) Tj (Color.red: 1) Tj (>) Tj (\),) Tj T* ( \('green', ) Tj (<) Tj (Color.green: 2) Tj (>) Tj (\),) Tj T* ( \('blue', ) Tj (<) Tj (Color.blue: 3) Tj (>) Tj (\),) Tj T* ( \('opacity', ) Tj (<) Tj (Color.opacity: 4) Tj (>) Tj (\)) Tj T* ( ]\)) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 649.8236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (constant) Tj T* ET Q Q q 1 0 0 1 62.69291 631.8236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (If you need to have some constant value in your ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( that isn't a member, use ) Tj /F2 10 Tf (constant) Tj /F1 10 Tf (:) Tj T* ET Q Q q 1 0 0 1 62.69291 310.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 312 re B* Q q BT 1 0 0 1 0 290 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( from aenum import constant) Tj T* (>) Tj (>) Tj (>) Tj ( class Planet\(Enum\):) Tj T* (... MERCURY = \(3.303e+23, 2.4397e6\)) Tj T* (... EARTH = \(5.976e+24, 6.37814e6\)) Tj T* (... JUPITER = \(1.9e+27, 7.1492e7\)) Tj T* (... URANUS = \(8.686e+25, 2.5559e7\)) Tj T* (... G = constant\(6.67300E-11\)) Tj T* (... def __init__\(self, mass, radius\):) Tj T* (... self.mass = mass # in kilograms) Tj T* (... self.radius = radius # in meters) Tj T* (... @property) Tj T* (... def surface_gravity\(self\):) Tj T* (... # universal gravitational constant \(m3 kg-1 s-2\)) Tj T* (... return self.G * self.mass / \(self.radius * self.radius\)) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( Planet.EARTH.value) Tj T* (\(5.976e+24, 6378140.0\)) Tj T* (>) Tj (>) Tj (>) Tj ( Planet.EARTH.surface_gravity) Tj T* (9.802652743337129) Tj T* (>) Tj (>) Tj (>) Tj ( Planet.G) Tj T* (6.673e-11) Tj T* (>) Tj (>) Tj (>) Tj ( Planet.G = 9) Tj T* (Traceback \(most recent call last\):) Tj T* (...) Tj T* (AttributeError: Planet: cannot rebind constant 'G') Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 280.6236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (skip) Tj T* ET Q Q q 1 0 0 1 62.69291 262.6236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (If you need a standard attribute that is not converted into an ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( member, use ) Tj /F2 10 Tf (skip) Tj /F1 10 Tf (:) Tj T* ET Q Q q 1 0 0 1 62.69291 97.42362 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 156 re B* Q q BT 1 0 0 1 0 134 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( from aenum import skip) Tj T* (>) Tj (>) Tj (>) Tj ( class Color\(Enum\):) Tj T* (... red = 1) Tj T* (... green = 2) Tj T* (... blue = 3) Tj T* (... opacity = skip\(0.45\)) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( Color.opacity) Tj T* (0.45) Tj T* (>) Tj (>) Tj (>) Tj ( Color.opacity = 0.77) Tj T* (>) Tj (>) Tj (>) Tj ( Color.opacity) Tj T* (0.77) Tj T* ET Q Q Q Q Q endstream endobj 103 0 obj << /Length 4095 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 747.0236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (start) Tj T* ET Q Q q 1 0 0 1 62.69291 717.0236 cm q BT 1 0 0 1 0 14 Tm 2.396235 Tw 12 TL /F2 10 Tf 0 0 0 rg (start) Tj /F1 10 Tf ( can be used to turn on auto-numbering \(useful for when you don't care which numbers are) Tj T* 0 Tw (assigned as long as they are consistent and in order\) The Python 3 version can look like this:) Tj T* ET Q Q q 1 0 0 1 62.69291 635.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 72 re B* Q q BT 1 0 0 1 0 50 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class Color\(Enum, start=1\): # doctest: +SKIP) Tj T* (... red, green, blue) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( Color.blue) Tj T* (<) Tj (Color.blue: 3) Tj (>) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 615.8236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (This can also be done in Python 2, albeit not as elegantly \(this also works in Python 3\):) Tj T* ET Q Q q 1 0 0 1 62.69291 498.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 108 re B* Q q BT 1 0 0 1 0 86 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class Color\(Enum\): # doctest: +SKIP) Tj T* (... _start_ = 1) Tj T* (... red = auto\(\)) Tj T* (... green = auto\(\)) Tj T* (... blue = auto\(\)) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( Color.blue) Tj T* (<) Tj (Color.blue: 3) Tj (>) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 468.6236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (init) Tj T* ET Q Q q 1 0 0 1 62.69291 450.6236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (If you need an ) Tj /F2 10 Tf (__init__) Tj /F1 10 Tf ( method that does nothing besides save its arguments, ) Tj /F2 10 Tf (init) Tj /F1 10 Tf ( is for you:) Tj T* ET Q Q q 1 0 0 1 62.69291 249.4236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 192 re B* Q q BT 1 0 0 1 0 170 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class Planet\(Enum, init='mass radius'\): # doctest: +SKIP) Tj T* (... MERCURY = \(3.303e+23, 2.4397e6\)) Tj T* (... EARTH = \(5.976e+24, 6.37814e6\)) Tj T* (... JUPITER = \(1.9e+27, 7.1492e7\)) Tj T* (... URANUS = \(8.686e+25, 2.5559e7\)) Tj T* (... G = constant\(6.67300E-11\)) Tj T* (... @property) Tj T* (... def surface_gravity\(self\):) Tj T* (... # universal gravitational constant \(m3 kg-1 s-2\)) Tj T* (... return self.G * self.mass / \(self.radius * self.radius\)) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( Planet.JUPITER.value) Tj T* (\(1.9e+27, 71492000.0\)) Tj T* (>) Tj (>) Tj (>) Tj ( Planet.JUPITER.mass) Tj T* (1.9e+27) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 229.4236 cm Q q 1 0 0 1 62.69291 146.4236 cm .960784 .960784 .862745 rg n 0 83 469.8898 -83 re f* 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 6 57 Tm T* ET q 1 0 0 1 16 52 cm q 0 0 0 rg BT 1 0 0 1 0 2.5 Tm /F4 12.5 Tf 15 TL (Note) Tj T* ET Q Q q 1 0 0 1 16 16 cm q BT 1 0 0 1 0 14 Tm -0.115512 Tw 12 TL /F1 10 Tf 0 0 0 rg (Just as with ) Tj /F2 10 Tf (start) Tj /F1 10 Tf ( above, in Python 2 you must put the keyword as a _sunder_ in the class body --) Tj T* 0 Tw /F2 10 Tf (_init_) Tj ( ) Tj (=) Tj ( ) Tj ('mass) Tj ( ) Tj (radius') Tj /F1 10 Tf (.) Tj T* ET Q Q q 1 J 1 j .662745 .662745 .662745 RG .5 w n 0 83 m 469.8898 83 l S n 0 0 m 469.8898 0 l S n 0 0 m 0 83 l S n 469.8898 0 m 469.8898 83 l S Q Q q 1 0 0 1 62.69291 140.4236 cm Q q 1 0 0 1 62.69291 110.4236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (init and missing values) Tj T* ET Q Q q 1 0 0 1 62.69291 80.42362 cm q BT 1 0 0 1 0 14 Tm .692485 Tw 12 TL /F1 10 Tf 0 0 0 rg (If ) Tj /F2 10 Tf (_init_) Tj /F1 10 Tf ( calls for values that are not supplied, ) Tj /F2 10 Tf (_generate_next_value_) Tj /F1 10 Tf ( will be called in an effort to) Tj T* 0 Tw (generate them. Here is an example in Python 2:) Tj T* ET Q Q endstream endobj 104 0 obj << /Length 3289 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 407.8599 cm q q .988825 0 0 .988825 0 0 cm q 1 0 0 1 6.6 6.674587 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 474 360 re B* Q q BT 1 0 0 1 0 338 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( from aenum import Enum) Tj T* (>) Tj (>) Tj (>) Tj ( class SelectionEnum\(Enum\):) Tj T* (... _init_ = 'db user') Tj T* (... def __new__\(cls, *args, **kwds\):) Tj T* (... count = len\(cls.__members__\)) Tj T* (... obj = object.__new__\(cls\)) Tj T* (... obj._count = count) Tj T* (... obj._value_ = args) Tj T* (... return obj) Tj T* (... @staticmethod) Tj T* (... def _generate_next_value_\(name, start, count, values, *args, **kwds\):) Tj T* (... return \(name, \) + args) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( class NotificationType\(SelectionEnum\):) Tj T* (... # usually, name is the same as db) Tj T* (... # but not for blanks) Tj T* (... blank = '', '') Tj T* (... C = 'Catalog') Tj T* (... S = 'Sheet') Tj T* (... B = 'Both') Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( NotificationType.blank) Tj T* (<) Tj (NotificationType.blank: \('', ''\)) Tj (>) Tj T* (>) Tj (>) Tj (>) Tj ( NotificationType.B) Tj T* (<) Tj (NotificationType.B: \('B', 'Both'\)) Tj (>) Tj T* (>) Tj (>) Tj (>) Tj ( NotificationType.B.db) Tj T* ('B') Tj T* (>) Tj (>) Tj (>) Tj ( NotificationType.B.user) Tj T* ('Both') Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 377.8599 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (combining Flag with other data types) Tj T* ET Q Q q 1 0 0 1 62.69291 335.8599 cm q BT 1 0 0 1 0 26 Tm 3.173735 Tw 12 TL /F1 10 Tf 0 0 0 rg (Flag does support being combined with other data types. To support this you need to provide a) Tj T* 0 Tw .111647 Tw /F2 10 Tf (_create_pseudo_member_values_) Tj /F1 10 Tf ( method which will be called with the members in a composite flag.) Tj T* 0 Tw (You may also need to provide a custom ) Tj /F2 10 Tf (__new__) Tj /F1 10 Tf ( method:) Tj T* ET Q Q q 1 0 0 1 62.69291 86.65994 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 240 re B* Q q BT 1 0 0 1 0 218 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class AnsiFlag\(str, Flag\):) Tj T* (... def __new__\(cls, value, code\):) Tj T* (... str_value = '\\x1b[%sm' % code) Tj T* (... obj = str.__new__\(cls, str_value\)) Tj T* (... obj._value_ = value) Tj T* (... obj.code = code) Tj T* (... return obj) Tj T* (... @classmethod) Tj T* (... def _create_pseudo_member_values_\(cls, members, *values\):) Tj T* (... code = ';'.join\(m.code for m in members\)) Tj T* (... return values + \(code, \)) Tj T* (... _order_ = 'FG_Red FG_Green BG_Magenta BG_White') Tj T* (... FG_Red = '31' # ESC [ 31 m # red) Tj T* (... FG_Green = '32' # ESC [ 32 m # green) Tj T* (... BG_Magenta = '45' # ESC [ 35 m # magenta) Tj T* (... BG_White = '47' # ESC [ 37 m # white) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( color = AnsiFlag.BG_White | AnsiFlag.FG_Red) Tj T* (>) Tj (>) Tj (>) Tj ( repr\(color\)) Tj T* ET Q Q Q Q Q endstream endobj 105 0 obj << /Length 3815 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 715.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 48 re B* Q q BT 1 0 0 1 0 26 Tm 12 TL /F2 10 Tf 0 0 0 rg (') Tj (<) Tj (AnsiFlag.FG_Red|BG_White: 9) Tj (>) Tj (') Tj T* (>) Tj (>) Tj (>) Tj ( str.__repr__\(color\)) Tj T* ("'\\\\x1b[31;47m'") Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 695.8236 cm Q q 1 0 0 1 62.69291 612.8236 cm .960784 .960784 .862745 rg n 0 83 469.8898 -83 re f* 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 6 57 Tm T* ET q 1 0 0 1 16 52 cm q 0 0 0 rg BT 1 0 0 1 0 2.5 Tm /F4 12.5 Tf 15 TL (Note) Tj T* ET Q Q q 1 0 0 1 16 16 cm q BT 1 0 0 1 0 14 Tm .360814 Tw 12 TL /F1 10 Tf 0 0 0 rg (If you do not provide your own ) Tj /F2 10 Tf (_create_pseudo_member_values_) Tj /F1 10 Tf ( the flags may still combine,) Tj T* 0 Tw (but may be missing functionality.) Tj T* ET Q Q q 1 J 1 j .662745 .662745 .662745 RG .5 w n 0 83 m 469.8898 83 l S n 0 0 m 469.8898 0 l S n 0 0 m 0 83 l S n 469.8898 0 m 469.8898 83 l S Q Q q 1 0 0 1 62.69291 606.8236 cm Q q 1 0 0 1 62.69291 573.8236 cm q BT 1 0 0 1 0 3.5 Tm 21 TL /F3 17.5 Tf 0 0 0 rg (Decorators) Tj T* ET Q Q q 1 0 0 1 62.69291 543.8236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (unique) Tj T* ET Q Q q 1 0 0 1 62.69291 513.8236 cm q BT 1 0 0 1 0 14 Tm .872706 Tw 12 TL /F1 10 Tf 0 0 0 rg (A ) Tj /F2 10 Tf (class) Tj /F1 10 Tf ( decorator specifically for enumerations. It searches an enumeration's ) Tj /F2 10 Tf (__members__) Tj /F1 10 Tf ( gathering) Tj T* 0 Tw (any aliases it finds; if any are found ) Tj /F2 10 Tf (ValueError) Tj /F1 10 Tf ( is raised with the details:) Tj T* ET Q Q q 1 0 0 1 62.69291 396.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 108 re B* Q q BT 1 0 0 1 0 86 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( @unique) Tj T* (... class NoDupes\(Enum\):) Tj T* (... first = 'one') Tj T* (... second = 'two') Tj T* (... third = 'two') Tj T* (Traceback \(most recent call last\):) Tj T* (...) Tj T* (ValueError: duplicate names found in ) Tj (<) Tj (aenum 'NoDupes') Tj (>) Tj (: third -) Tj (>) Tj ( second) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 363.6236 cm q BT 1 0 0 1 0 3.5 Tm 21 TL /F3 17.5 Tf 0 0 0 rg (Interesting examples) Tj T* ET Q Q q 1 0 0 1 62.69291 321.6236 cm q BT 1 0 0 1 0 26 Tm .996235 Tw 12 TL /F1 10 Tf 0 0 0 rg (While ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( and ) Tj /F2 10 Tf (IntEnum) Tj /F1 10 Tf ( are expected to cover the majority of use-cases, they cannot cover them all.) Tj T* 0 Tw 1.256457 Tw (Here are recipes for some different types of enumerations that can be used directly \(the first three are) Tj T* 0 Tw (included in the module\), or as examples for creating one's own.) Tj T* ET Q Q q 1 0 0 1 62.69291 291.6236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (AutoNumber) Tj T* ET Q Q q 1 0 0 1 62.69291 273.6236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (Avoids having to specify the value for each enumeration member:) Tj T* ET Q Q q 1 0 0 1 62.69291 96.42362 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 168 re B* Q q BT 1 0 0 1 0 146 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class AutoNumber\(Enum\):) Tj T* (... def __new__\(cls\):) Tj T* (... value = len\(cls.__members__\) + 1) Tj T* (... obj = object.__new__\(cls\)) Tj T* (... obj._value_ = value) Tj T* (... return obj) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( class Color\(AutoNumber\):) Tj T* (... _order_ = "red green blue" # only needed in 2.x) Tj T* (... red = \(\)) Tj T* (... green = \(\)) Tj T* (... blue = \(\)) Tj T* (...) Tj T* ET Q Q Q Q Q endstream endobj 106 0 obj << /Length 3915 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 727.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 36 re B* Q q BT 1 0 0 1 0 14 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( Color.green.value == 2) Tj T* (True) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 707.8236 cm Q q 1 0 0 1 62.69291 600.8236 cm .960784 .960784 .862745 rg n 0 107 469.8898 -107 re f* 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 6 81 Tm T* ET q 1 0 0 1 16 76 cm q 0 0 0 rg BT 1 0 0 1 0 2.5 Tm /F4 12.5 Tf 15 TL (Note) Tj T* ET Q Q q 1 0 0 1 16 16 cm q BT 1 0 0 1 0 38 Tm .23686 Tw 12 TL /F1 10 Tf 0 0 0 rg (The ) Tj /F5 10 Tf (__new__) Tj /F1 10 Tf ( method, if defined, is used during creation of the Enum members; it is then replaced) Tj T* 0 Tw .501235 Tw (by Enum's ) Tj /F5 10 Tf (__new__) Tj /F1 10 Tf ( which is used after class creation for lookup of existing members. Due to the) Tj T* 0 Tw 2.199269 Tw (way Enums are supposed to behave, there is no way to customize Enum's ) Tj /F5 10 Tf (__new__) Tj /F1 10 Tf ( without) Tj T* 0 Tw (modifying the class after it is created.) Tj T* ET Q Q q 1 J 1 j .662745 .662745 .662745 RG .5 w n 0 107 m 469.8898 107 l S n 0 0 m 469.8898 0 l S n 0 0 m 0 107 l S n 469.8898 0 m 469.8898 107 l S Q Q q 1 0 0 1 62.69291 594.8236 cm Q q 1 0 0 1 62.69291 564.8236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (UniqueEnum) Tj T* ET Q Q q 1 0 0 1 62.69291 546.8236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (Raises an error if a duplicate member name is found instead of creating an alias:) Tj T* ET Q Q q 1 0 0 1 62.69291 297.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 240 re B* Q q BT 1 0 0 1 0 218 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class UniqueEnum\(Enum\):) Tj T* (... def __init__\(self, *args\):) Tj T* (... cls = self.__class__) Tj T* (... if any\(self.value == e.value for e in cls\):) Tj T* (... a = self.name) Tj T* (... e = cls\(self.value\).name) Tj T* (... raise ValueError\() Tj T* (... "aliases not allowed in UniqueEnum: %r --) Tj (>) Tj ( %r") Tj T* (... % \(a, e\)\)) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( class Color\(UniqueEnum\):) Tj T* (... _order_ = 'red green blue') Tj T* (... red = 1) Tj T* (... green = 2) Tj T* (... blue = 3) Tj T* (... grene = 2) Tj T* (Traceback \(most recent call last\):) Tj T* (...) Tj T* (ValueError: aliases not allowed in UniqueEnum: 'grene' --) Tj (>) Tj ( 'green') Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 267.6236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (OrderedEnum) Tj T* ET Q Q q 1 0 0 1 62.69291 237.6236 cm q BT 1 0 0 1 0 14 Tm -0.04689 Tw 12 TL /F1 10 Tf 0 0 0 rg (An ordered enumeration that is not based on ) Tj /F2 10 Tf (IntEnum) Tj /F1 10 Tf ( and so maintains the normal ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( invariants \(such) Tj T* 0 Tw (as not being comparable to other enumerations\):) Tj T* ET Q Q q 1 0 0 1 62.69291 84.42362 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 144 re B* Q q BT 1 0 0 1 0 122 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class OrderedEnum\(Enum\):) Tj T* (... def __ge__\(self, other\):) Tj T* (... if self.__class__ is other.__class__:) Tj T* (... return self._value_ ) Tj (>) Tj (= other._value_) Tj T* (... return NotImplemented) Tj T* (... def __gt__\(self, other\):) Tj T* (... if self.__class__ is other.__class__:) Tj T* (... return self._value_ ) Tj (>) Tj ( other._value_) Tj T* (... return NotImplemented) Tj T* (... def __le__\(self, other\):) Tj T* (... if self.__class__ is other.__class__:) Tj T* ET Q Q Q Q Q endstream endobj 107 0 obj << /Length 2874 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 547.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 216 re B* Q q BT 1 0 0 1 0 194 Tm 12 TL /F2 10 Tf 0 0 0 rg (... return self._value_ ) Tj (<) Tj (= other._value_) Tj T* (... return NotImplemented) Tj T* (... def __lt__\(self, other\):) Tj T* (... if self.__class__ is other.__class__:) Tj T* (... return self._value_ ) Tj (<) Tj ( other._value_) Tj T* (... return NotImplemented) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( class Grade\(OrderedEnum\):) Tj T* (... __ordered__ = 'A B C D F') Tj T* (... A = 5) Tj T* (... B = 4) Tj T* (... C = 3) Tj T* (... D = 2) Tj T* (... F = 1) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( Grade.C ) Tj (<) Tj ( Grade.A) Tj T* (True) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 517.8236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (Planet) Tj T* ET Q Q q 1 0 0 1 62.69291 499.8236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (If ) Tj /F2 10 Tf (__new__) Tj /F1 10 Tf ( or ) Tj /F2 10 Tf (__init__) Tj /F1 10 Tf ( is defined the value of the enum member will be passed to those methods:) Tj T* ET Q Q q 1 0 0 1 62.69291 214.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 276 re B* Q q BT 1 0 0 1 0 254 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class Planet\(Enum\):) Tj T* (... MERCURY = \(3.303e+23, 2.4397e6\)) Tj T* (... VENUS = \(4.869e+24, 6.0518e6\)) Tj T* (... EARTH = \(5.976e+24, 6.37814e6\)) Tj T* (... MARS = \(6.421e+23, 3.3972e6\)) Tj T* (... JUPITER = \(1.9e+27, 7.1492e7\)) Tj T* (... SATURN = \(5.688e+26, 6.0268e7\)) Tj T* (... URANUS = \(8.686e+25, 2.5559e7\)) Tj T* (... NEPTUNE = \(1.024e+26, 2.4746e7\)) Tj T* (... def __init__\(self, mass, radius\):) Tj T* (... self.mass = mass # in kilograms) Tj T* (... self.radius = radius # in meters) Tj T* (... @property) Tj T* (... def surface_gravity\(self\):) Tj T* (... # universal gravitational constant \(m3 kg-1 s-2\)) Tj T* (... G = 6.67300E-11) Tj T* (... return G * self.mass / \(self.radius * self.radius\)) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( Planet.EARTH.value) Tj T* (\(5.976e+24, 6378140.0\)) Tj T* (>) Tj (>) Tj (>) Tj ( Planet.EARTH.surface_gravity) Tj T* (9.802652743337129) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 181.6236 cm q BT 1 0 0 1 0 3.5 Tm 21 TL /F3 17.5 Tf 0 0 0 rg (How are Enums different?) Tj T* ET Q Q q 1 0 0 1 62.69291 151.6236 cm q 0 0 0 rg BT 1 0 0 1 0 14 Tm /F1 10 Tf 12 TL 2.090651 Tw (Enums have a custom metaclass that affects many aspects of both derived Enum classes and their) Tj T* 0 Tw (instances \(members\).) Tj T* ET Q Q endstream endobj 108 0 obj << /Length 5719 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 747.0236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (Enum Classes) Tj T* ET Q Q q 1 0 0 1 62.69291 681.0236 cm q BT 1 0 0 1 0 50 Tm 1.849069 Tw 12 TL /F1 10 Tf 0 0 0 rg (The ) Tj /F2 10 Tf (EnumMeta) Tj /F1 10 Tf ( metaclass is responsible for providing the ) Tj /F2 10 Tf (__contains__) Tj /F1 10 Tf (, ) Tj /F2 10 Tf (__dir__) Tj /F1 10 Tf (, ) Tj /F2 10 Tf (__iter__) Tj /F1 10 Tf ( and) Tj T* 0 Tw 2.434198 Tw (other methods that allow one to do things with an ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( class that fail on a typical class, such as) Tj T* 0 Tw 2.86248 Tw /F2 10 Tf (list\(Color\)) Tj /F1 10 Tf ( or ) Tj /F2 10 Tf (some_var) Tj ( ) Tj (in) Tj ( ) Tj (Color) Tj /F1 10 Tf (. ) Tj /F2 10 Tf (EnumMeta) Tj /F1 10 Tf ( is responsible for ensuring that various other) Tj T* 0 Tw 2.69229 Tw (methods on the final ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( class are correct \(such as ) Tj /F2 10 Tf (__new__) Tj /F1 10 Tf (, ) Tj /F2 10 Tf (__getnewargs__) Tj /F1 10 Tf (, ) Tj /F2 10 Tf (__str__) Tj /F1 10 Tf ( and) Tj T* 0 Tw /F2 10 Tf (__repr__) Tj /F1 10 Tf (\).) Tj T* ET Q Q q 1 0 0 1 62.69291 669.0236 cm Q q 1 0 0 1 62.69291 586.0236 cm .960784 .960784 .862745 rg n 0 83 469.8898 -83 re f* 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 6 57 Tm T* ET q 1 0 0 1 16 52 cm q 0 0 0 rg BT 1 0 0 1 0 2.5 Tm /F4 12.5 Tf 15 TL (Note) Tj T* ET Q Q q 1 0 0 1 16 16 cm q BT 1 0 0 1 0 14 Tm .686654 Tw 12 TL /F2 10 Tf 0 0 0 rg (__dir__) Tj /F1 10 Tf ( is not changed in the Python 2 line as it messes up some of the decorators included in) Tj T* 0 Tw (the stdlib.) Tj T* ET Q Q q 1 J 1 j .662745 .662745 .662745 RG .5 w n 0 83 m 469.8898 83 l S n 0 0 m 469.8898 0 l S n 0 0 m 0 83 l S n 469.8898 0 m 469.8898 83 l S Q Q q 1 0 0 1 62.69291 580.0236 cm Q q 1 0 0 1 62.69291 550.0236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (Enum Members \(aka instances\)) Tj T* ET Q Q q 1 0 0 1 62.69291 508.0236 cm q BT 1 0 0 1 0 26 Tm .706651 Tw 12 TL /F1 10 Tf 0 0 0 rg (The most interesting thing about Enum members is that they are singletons. ) Tj /F2 10 Tf (EnumMeta) Tj /F1 10 Tf ( creates them all) Tj T* 0 Tw .406988 Tw (while it is creating the ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( class itself, and then puts a custom ) Tj /F2 10 Tf (__new__) Tj /F1 10 Tf ( in place to ensure that no new) Tj T* 0 Tw (ones are ever instantiated by returning only the existing member instances.) Tj T* ET Q Q q 1 0 0 1 62.69291 478.0236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (Finer Points) Tj T* ET Q Q q 1 0 0 1 62.69291 448.0236 cm q BT 1 0 0 1 0 14 Tm .476905 Tw 12 TL /F2 10 Tf 0 0 0 rg (Enum) Tj /F1 10 Tf ( members are instances of an ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( class, and are accessible as ) Tj /F5 10 Tf (EnumClass.member1.member2) Tj /F1 10 Tf ( --) Tj T* 0 Tw (but only if no other constant/property exists:) Tj T* ET Q Q q 1 0 0 1 62.69291 294.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 144 re B* Q q BT 1 0 0 1 0 122 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class FieldTypes\(Enum\):) Tj T* (... name = 1) Tj T* (... value = 2) Tj T* (... size = 3) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( FieldTypes.size) Tj T* (<) Tj (FieldTypes.size: 3) Tj (>) Tj T* (>) Tj (>) Tj (>) Tj ( FieldTypes.value.size) Tj T* (<) Tj (FieldTypes.size: 3) Tj (>) Tj T* (>) Tj (>) Tj (>) Tj ( FieldTypes.size.value # NOT ) Tj (<) Tj (FieldTypes.value: 2) Tj (>) Tj T* (3) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 274.8236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (The ) Tj /F2 10 Tf (__members__) Tj /F1 10 Tf ( attribute is only available on the class.) Tj T* ET Q Q q 1 0 0 1 62.69291 232.8236 cm q BT 1 0 0 1 0 26 Tm .62186 Tw 12 TL /F2 10 Tf 0 0 0 rg (__members__) Tj /F1 10 Tf ( is always an ) Tj /F2 10 Tf (OrderedDict) Tj /F1 10 Tf (, with the order being the definition order in Python 3.x or the) Tj T* 0 Tw 3.571163 Tw (order in ) Tj /F2 10 Tf (_order_) Tj /F1 10 Tf ( in Python 2.7; if no ) Tj /F2 10 Tf (_order_) Tj /F1 10 Tf ( was specified in Python 2.7 then the order of) Tj T* 0 Tw /F2 10 Tf (__members__) Tj /F1 10 Tf ( is either increasing value or alphabetically by name.) Tj T* ET Q Q q 1 0 0 1 62.69291 202.8236 cm q BT 1 0 0 1 0 14 Tm .285542 Tw 12 TL /F1 10 Tf 0 0 0 rg (If you give your ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( subclass extra methods, like the ) Tj 0 0 .501961 rg (Planet) Tj 0 0 0 rg ( class above, those methods will show up in) Tj T* 0 Tw (a ) Tj /F5 10 Tf (dir) Tj /F1 10 Tf ( of the member, but not of the class \(in Python 3.x\):) Tj T* ET Q Q q 1 0 0 1 62.69291 121.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 72 re B* Q q BT 1 0 0 1 0 50 Tm 12 TL /F2 10 Tf 0 0 0 rg (--) Tj (>) Tj ( dir\(Planet\)) Tj T* (['EARTH', 'JUPITER', 'MARS', 'MERCURY', 'NEPTUNE', 'SATURN', 'URANUS',) Tj T* ( 'VENUS', '__class__', '__doc__', '__members__', '__module__']) Tj T* (--) Tj (>) Tj ( dir\(Planet.EARTH\)) Tj T* (['__class__', '__doc__', '__module__', 'name', 'surface_gravity', 'value']) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 77.62362 cm q BT 1 0 0 1 0 26 Tm .130488 Tw 12 TL /F1 10 Tf 0 0 0 rg (A ) Tj /F2 10 Tf (__new__) Tj /F1 10 Tf ( method will only be used for the creation of the ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( members -- after that it is replaced. This) Tj T* 0 Tw .269988 Tw (means if you wish to change how ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( members are looked up you either have to write a helper function) Tj T* 0 Tw (or a ) Tj /F2 10 Tf (classmethod) Tj /F1 10 Tf (.) Tj T* ET Q Q q 1 0 0 1 62.69291 76.86614 cm Q endstream endobj 109 0 obj << /Length 4234 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 682.0236 cm .960784 .960784 .862745 rg n 0 83 469.8898 -83 re f* 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 6 57 Tm T* ET q 1 0 0 1 16 52 cm q 0 0 0 rg BT 1 0 0 1 0 2.5 Tm /F4 12.5 Tf 15 TL (Note) Tj T* ET Q Q q 1 0 0 1 16 16 cm q BT 1 0 0 1 0 14 Tm .352488 Tw 12 TL /F1 10 Tf 0 0 0 rg (If you create your own ) Tj /F2 10 Tf (__new__) Tj /F1 10 Tf ( you should set the ) Tj /F2 10 Tf (_value_) Tj /F1 10 Tf ( in it; if you do not, aenum will try to,) Tj T* 0 Tw (but will raise a ) Tj /F2 10 Tf (TypeError) Tj /F1 10 Tf ( if it cannot.) Tj T* ET Q Q q 1 J 1 j .662745 .662745 .662745 RG .5 w n 0 83 m 469.8898 83 l S n 0 0 m 469.8898 0 l S n 0 0 m 0 83 l S n 469.8898 0 m 469.8898 83 l S Q Q q 1 0 0 1 62.69291 676.0236 cm Q q 1 0 0 1 62.69291 646.0236 cm q BT 1 0 0 1 0 14 Tm .86528 Tw 12 TL /F1 10 Tf 0 0 0 rg (If the stdlib ) Tj /F2 10 Tf (enum) Tj /F1 10 Tf ( is available \(Python 3.4+ and it hasn't been shadowed by, for example, ) Tj /F2 10 Tf (enum34) Tj /F1 10 Tf (\) then) Tj T* 0 Tw (aenum will be a subclass of it.) Tj T* ET Q Q q 1 0 0 1 62.69291 616.0236 cm q BT 1 0 0 1 0 14 Tm 1.338555 Tw 12 TL /F1 10 Tf 0 0 0 rg (To use the ) Tj /F2 10 Tf (AddValue) Tj /F1 10 Tf (, ) Tj /F2 10 Tf (MultiValue) Tj /F1 10 Tf (, ) Tj /F2 10 Tf (NoAlias) Tj /F1 10 Tf (, and ) Tj /F2 10 Tf (Unique) Tj /F1 10 Tf ( flags in Py2 or Py2/Py3 codebases, use) Tj T* 0 Tw /F2 10 Tf (_settings_) Tj ( ) Tj (=) Tj ( ) Tj (...) Tj /F1 10 Tf ( in the class body.) Tj T* ET Q Q q 1 0 0 1 62.69291 598.0236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (To use ) Tj /F2 10 Tf (init) Tj /F1 10 Tf ( in Py2 or Py2/Py3 codebases use ) Tj /F2 10 Tf (_init_) Tj /F1 10 Tf ( in the class body.) Tj T* ET Q Q q 1 0 0 1 62.69291 580.0236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (To use ) Tj /F2 10 Tf (start) Tj /F1 10 Tf ( in Py2 or Py2/Py3 codebases use ) Tj /F2 10 Tf (_start_) Tj /F1 10 Tf ( in the class body.) Tj T* ET Q Q q 1 0 0 1 62.69291 562.0236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (When creating class bodies dynamically, put any variables you need to use into ) Tj /F2 10 Tf (_ignore_) Tj /F1 10 Tf (:) Tj T* ET Q Q q 1 0 0 1 62.69291 288.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 264 re B* Q q BT 1 0 0 1 0 242 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( from datetime import timedelta) Tj T* (>) Tj (>) Tj (>) Tj ( from aenum import NoAlias) Tj T* (>) Tj (>) Tj (>) Tj ( class Period\(timedelta, Enum\):) Tj T* (... ''') Tj T* (... different lengths of time) Tj T* (... ''') Tj T* (... _init_ = 'value period') Tj T* (... _settings_ = NoAlias) Tj T* (... _ignore_ = 'Period i') Tj T* (... Period = vars\(\)) Tj T* (... for i in range\(31\):) Tj T* (... Period['day_%d' % i] = i, 'day') Tj T* (... for i in range\(15\):) Tj T* (... Period['week_%d' % i] = i*7, 'week') Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( hasattr\(Period, '_ignore_'\)) Tj T* (False) Tj T* (>) Tj (>) Tj (>) Tj ( hasattr\(Period, 'Period'\)) Tj T* (False) Tj T* (>) Tj (>) Tj (>) Tj ( hasattr\(Period, 'i'\)) Tj T* (False) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 256.8236 cm q BT 1 0 0 1 0 14 Tm .42332 Tw 12 TL /F1 10 Tf 0 0 0 rg (The name listed in ) Tj /F2 10 Tf (_ignore_) Tj /F1 10 Tf (, as well as ) Tj /F2 10 Tf (_ignore_) Tj /F1 10 Tf ( itself, will not be present in the final enumeration as) Tj T* 0 Tw (neither attributes nor members.) Tj T* ET Q Q q 1 0 0 1 62.69291 244.8236 cm Q q 1 0 0 1 62.69291 161.8236 cm .960784 .960784 .862745 rg n 0 83 469.8898 -83 re f* 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 6 57 Tm T* ET q 1 0 0 1 16 52 cm q 0 0 0 rg BT 1 0 0 1 0 2.5 Tm /F4 12.5 Tf 15 TL (Note) Tj T* ET Q Q q 1 0 0 1 16 16 cm q 0 0 0 rg BT 1 0 0 1 0 14 Tm /F1 10 Tf 12 TL .333059 Tw (except for __dunder__ attributes/methods, all _sunder_ attributes must be before any thing else in) Tj T* 0 Tw (the class body) Tj T* ET Q Q q 1 J 1 j .662745 .662745 .662745 RG .5 w n 0 83 m 469.8898 83 l S n 0 0 m 469.8898 0 l S n 0 0 m 0 83 l S n 469.8898 0 m 469.8898 83 l S Q Q q 1 0 0 1 62.69291 155.8236 cm Q q 1 0 0 1 62.69291 143.8236 cm Q endstream endobj 110 0 obj << /Length 4886 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 682.0236 cm .960784 .960784 .862745 rg n 0 83 469.8898 -83 re f* 0 0 0 rg BT /F1 10 Tf 12 TL ET BT 1 0 0 1 6 57 Tm T* ET q 1 0 0 1 16 52 cm q 0 0 0 rg BT 1 0 0 1 0 2.5 Tm /F4 12.5 Tf 15 TL (Note) Tj T* ET Q Q q 1 0 0 1 16 16 cm q BT 1 0 0 1 0 14 Tm .404985 Tw 12 TL /F1 10 Tf 0 0 0 rg (all _sunder_ attributes that affect member creation are only looked up in the last ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf ( class listed) Tj T* 0 Tw (in the class header) Tj T* ET Q Q q 1 J 1 j .662745 .662745 .662745 RG .5 w n 0 83 m 469.8898 83 l S n 0 0 m 469.8898 0 l S n 0 0 m 0 83 l S n 469.8898 0 m 469.8898 83 l S Q Q q 1 0 0 1 62.69291 676.0236 cm Q q 1 0 0 1 62.69291 643.0236 cm q BT 1 0 0 1 0 3.5 Tm 21 TL /F3 17.5 Tf 0 0 0 rg (Creating NamedTuples) Tj T* ET Q Q q 1 0 0 1 62.69291 613.0236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (Simple) Tj T* ET Q Q q 1 0 0 1 62.69291 595.0236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (The most common way to create a new NamedTuple will be via the functional API:) Tj T* ET Q Q q 1 0 0 1 62.69291 549.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 36 re B* Q q BT 1 0 0 1 0 14 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( from aenum import NamedTuple) Tj T* (>) Tj (>) Tj (>) Tj ( Book = NamedTuple\('Book', 'title author genre', module=__name__\)) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 517.8236 cm q BT 1 0 0 1 0 14 Tm 2.13061 Tw 12 TL /F1 10 Tf 0 0 0 rg (This creates a ) Tj /F2 10 Tf (NamedTuple) Tj /F1 10 Tf ( called ) Tj /F2 10 Tf (Book) Tj /F1 10 Tf ( that will always contain three items, each of which is also) Tj T* 0 Tw (addressable as ) Tj /F2 10 Tf (title) Tj /F1 10 Tf (, ) Tj /F2 10 Tf (author) Tj /F1 10 Tf (, or ) Tj /F2 10 Tf (genre) Tj /F1 10 Tf (.) Tj T* ET Q Q q 1 0 0 1 62.69291 499.8236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F2 10 Tf 0 0 0 rg (Book) Tj /F1 10 Tf ( instances can be created using positional or keyword argements or a mixture of the two:) Tj T* ET Q Q q 1 0 0 1 62.69291 442.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 48 re B* Q q BT 1 0 0 1 0 26 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( b1 = Book\('Lord of the Rings', 'J.R.R. Tolkien', 'fantasy'\)) Tj T* (>) Tj (>) Tj (>) Tj ( b2 = Book\(title='Jhereg', author='Steven Brust', genre='fantasy'\)) Tj T* (>) Tj (>) Tj (>) Tj ( b3 = Book\('Empire', 'Orson Scott Card', genre='scifi'\)) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 422.6236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (If too few or too many arguments are used a ) Tj /F2 10 Tf (TypeError) Tj /F1 10 Tf ( will be raised:) Tj T* ET Q Q q 1 0 0 1 62.69291 305.4236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 108 re B* Q q BT 1 0 0 1 0 86 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( b4 = Book\('Hidden Empire'\)) Tj T* (Traceback \(most recent call last\):) Tj T* (...) Tj T* (TypeError: values not provided for field\(s\): author, genre) Tj T* (>) Tj (>) Tj (>) Tj ( b5 = Book\(genre='business'\)) Tj T* (Traceback \(most recent call last\):) Tj T* (...) Tj T* (TypeError: values not provided for field\(s\): title, author) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 285.4236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (As a ) Tj /F2 10 Tf (class) Tj /F1 10 Tf ( the above ) Tj /F2 10 Tf (Book) Tj /F1 10 Tf ( ) Tj /F2 10 Tf (NamedTuple) Tj /F1 10 Tf ( would look like:) Tj T* ET Q Q q 1 0 0 1 62.69291 204.2236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 72 re B* Q q BT 1 0 0 1 0 50 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class Book\(NamedTuple\):) Tj T* (... title = 0) Tj T* (... author = 1) Tj T* (... genre = 2) Tj T* (...) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 172.2236 cm q BT 1 0 0 1 0 14 Tm 4.073314 Tw 12 TL /F1 10 Tf 0 0 0 rg (For compatibility with the stdlib ) Tj /F2 10 Tf (namedtuple) Tj /F1 10 Tf (, NamedTuple also has the ) Tj /F2 10 Tf (_asdict) Tj /F1 10 Tf (, ) Tj /F2 10 Tf (_make) Tj /F1 10 Tf (, and) Tj T* 0 Tw /F2 10 Tf (_replace) Tj /F1 10 Tf ( methods, and the ) Tj /F2 10 Tf (_fields) Tj /F1 10 Tf ( attribute, which all function similarly:) Tj T* ET Q Q q 1 0 0 1 62.69291 79.02362 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 84 re B* Q q BT 1 0 0 1 0 62 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class Point\(NamedTuple\):) Tj T* (... x = 0, 'horizontal coordinate', 1) Tj T* (... y = 1, 'vertical coordinate', -1) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( class Color\(NamedTuple\):) Tj T* (... r = 0, 'red component', 11) Tj T* ET Q Q Q Q Q endstream endobj 111 0 obj << /Length 3092 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 487.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 276 re B* Q q BT 1 0 0 1 0 254 Tm 12 TL /F2 10 Tf 0 0 0 rg (... g = 1, 'green component', 29) Tj T* (... b = 2, 'blue component', 37) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( Pixel = NamedTuple\('Pixel', Point+Color, module=__name__\)) Tj T* (>) Tj (>) Tj (>) Tj ( pixel = Pixel\(99, -101, 255, 128, 0\)) Tj T* T* (>) Tj (>) Tj (>) Tj ( pixel._asdict\(\)) Tj T* (OrderedDict\([\('x', 99\), \('y', -101\), \('r', 255\), \('g', 128\), \('b', 0\)]\)) Tj T* T* (>) Tj (>) Tj (>) Tj ( Point._make\(\(4, 5\)\)) Tj T* (Point\(x=4, y=5\)) Tj T* T* (>) Tj (>) Tj (>) Tj ( purple = Color\(127, 0, 127\)) Tj T* (>) Tj (>) Tj (>) Tj ( mid_gray = purple._replace\(g=127\)) Tj T* (>) Tj (>) Tj (>) Tj ( mid_gray) Tj T* (Color\(r=127, g=127, b=127\)) Tj T* T* (>) Tj (>) Tj (>) Tj ( pixel._fields) Tj T* (['x', 'y', 'r', 'g', 'b']) Tj T* T* (>) Tj (>) Tj (>) Tj ( Pixel._fields) Tj T* (['x', 'y', 'r', 'g', 'b']) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 457.8236 cm q BT 1 0 0 1 0 3 Tm 18 TL /F3 15 Tf 0 0 0 rg (Advanced) Tj T* ET Q Q q 1 0 0 1 62.69291 427.8236 cm q BT 1 0 0 1 0 14 Tm 1.515814 Tw 12 TL /F1 10 Tf 0 0 0 rg (The simple method of creating ) Tj /F2 10 Tf (NamedTuples) Tj /F1 10 Tf ( requires always specifying all possible arguments when) Tj T* 0 Tw (creating instances; failure to do so will raise exceptions:) Tj T* ET Q Q q 1 0 0 1 62.69291 214.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 204 re B* Q q BT 1 0 0 1 0 182 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class Point\(NamedTuple\):) Tj T* (... x = 0) Tj T* (... y = 1) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( Point\(\)) Tj T* (Traceback \(most recent call last\):) Tj T* (...) Tj T* (TypeError: values not provided for field\(s\): x, y) Tj T* (>) Tj (>) Tj (>) Tj ( Point\(1\)) Tj T* (Traceback \(most recent call last\):) Tj T* (...) Tj T* (TypeError: values not provided for field\(s\): y) Tj T* (>) Tj (>) Tj (>) Tj ( Point\(y=2\)) Tj T* (Traceback \(most recent call last\):) Tj T* (...) Tj T* (TypeError: values not provided for field\(s\): x) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 182.6236 cm q BT 1 0 0 1 0 14 Tm .535984 Tw 12 TL /F1 10 Tf 0 0 0 rg (However, it is possible to specify both docstrings and default values when creating a ) Tj /F2 10 Tf (NamedTuple) Tj /F1 10 Tf ( using) Tj T* 0 Tw (the class method:) Tj T* ET Q Q q 1 0 0 1 62.69291 77.42362 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 96 re B* Q q BT 1 0 0 1 0 74 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class Point\(NamedTuple\):) Tj T* (... x = 0, 'horizontal coordinate', 0) Tj T* (... y = 1, 'vertical coordinate', 0) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( Point\(\)) Tj T* (Point\(x=0, y=0\)) Tj T* (>) Tj (>) Tj (>) Tj ( Point\(1\)) Tj T* ET Q Q Q Q Q endstream endobj 112 0 obj << /Length 3719 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 715.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 48 re B* Q q BT 1 0 0 1 0 26 Tm 12 TL /F2 10 Tf 0 0 0 rg (Point\(x=1, y=0\)) Tj T* (>) Tj (>) Tj (>) Tj ( Point\(y=2\)) Tj T* (Point\(x=0, y=2\)) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 683.8236 cm q BT 1 0 0 1 0 14 Tm 1.238735 Tw 12 TL /F1 10 Tf 0 0 0 rg (It is also possible to create ) Tj /F2 10 Tf (NamedTuples) Tj /F1 10 Tf ( that only have named attributes for certain fields; any fields) Tj T* 0 Tw (without names can still be accessed by index:) Tj T* ET Q Q q 1 0 0 1 62.69291 470.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 204 re B* Q q BT 1 0 0 1 0 182 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class Person\(NamedTuple\):) Tj T* (... fullname = 2) Tj T* (... phone = 5) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( p = Person\('Ethan', 'Furman', 'Ethan Furman',) Tj T* (... 'ethan at stoneleaf dot us',) Tj T* (... 'ethan.furman', '999.555.1212'\)) Tj T* (>) Tj (>) Tj (>) Tj ( p) Tj T* (Person\('Ethan', 'Furman', 'Ethan Furman', 'ethan at stoneleaf dot us',) Tj T* ( 'ethan.furman', '999.555.1212'\)) Tj T* (>) Tj (>) Tj (>) Tj ( p.fullname) Tj T* ('Ethan Furman') Tj T* (>) Tj (>) Tj (>) Tj ( p.phone) Tj T* ('999.555.1212') Tj T* (>) Tj (>) Tj (>) Tj ( p[0]) Tj T* ('Ethan') Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 426.6236 cm q BT 1 0 0 1 0 26 Tm .261567 Tw 12 TL /F1 10 Tf 0 0 0 rg (In the above example the last named field was also the last field possible; in those cases where you don't) Tj T* 0 Tw 2.188651 Tw (need to have the last possible field named, you can provide a ) Tj /F2 10 Tf (_size_) Tj /F1 10 Tf ( of ) Tj /F2 10 Tf (TupleSize.minimum) Tj /F1 10 Tf ( to) Tj T* 0 Tw (declare that more fields are okay:) Tj T* ET Q Q q 1 0 0 1 62.69291 333.4236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 84 re B* Q q BT 1 0 0 1 0 62 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( from aenum import TupleSize) Tj T* (>) Tj (>) Tj (>) Tj ( class Person\(NamedTuple\):) Tj T* (... _size_ = TupleSize.minimum) Tj T* (... first = 0) Tj T* (... last = 1) Tj T* (...) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 313.4236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (or, optionally if using Python 3:) Tj T* ET Q Q q 1 0 0 1 62.69291 256.2236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 48 re B* Q q BT 1 0 0 1 0 26 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class Person\(NamedTuple, size=TupleSize.minimum\): # doctest: +SKIP) Tj T* (... first = 0) Tj T* (... last = 1) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 236.2236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (and in use:) Tj T* ET Q Q q 1 0 0 1 62.69291 83.02362 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 144 re B* Q q BT 1 0 0 1 0 122 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( Person\('Ethan', 'Furman'\)) Tj T* (Person\(first='Ethan', last='Furman'\)) Tj T* T* (>) Tj (>) Tj (>) Tj ( Person\('Ethan', 'Furman', 'ethan.furman'\)) Tj T* (Person\('Ethan', 'Furman', 'ethan.furman'\)) Tj T* T* (>) Tj (>) Tj (>) Tj ( Person\('Ethan', 'Furman', 'ethan.furman', 'yay Python!'\)) Tj T* (Person\('Ethan', 'Furman', 'ethan.furman', 'yay Python!'\)) Tj T* T* (>) Tj (>) Tj (>) Tj ( Person\('Ethan'\)) Tj T* (Traceback \(most recent call last\):) Tj T* ET Q Q Q Q Q endstream endobj 113 0 obj << /Length 3749 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 727.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 36 re B* Q q BT 1 0 0 1 0 14 Tm 12 TL /F2 10 Tf 0 0 0 rg (...) Tj T* (TypeError: values not provided for field\(s\): last) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 695.8236 cm q BT 1 0 0 1 0 14 Tm 7.162126 Tw 12 TL /F1 10 Tf 0 0 0 rg (Also, for those cases where even named fields may not be present, you can specify) Tj T* 0 Tw /F2 10 Tf (TupleSize.variable) Tj /F1 10 Tf (:) Tj T* ET Q Q q 1 0 0 1 62.69291 518.6236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 168 re B* Q q BT 1 0 0 1 0 146 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( class Person\(NamedTuple\):) Tj T* (... _size_ = TupleSize.variable) Tj T* (... first = 0) Tj T* (... last = 1) Tj T* (...) Tj T* T* (>) Tj (>) Tj (>) Tj ( Person\('Ethan'\)) Tj T* (Person\('Ethan'\)) Tj T* T* (>) Tj (>) Tj (>) Tj ( Person\(last='Furman'\)) Tj T* (Traceback \(most recent call last\):) Tj T* (...) Tj T* (TypeError: values not provided for field\(s\): first) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 498.6236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (Creating new ) Tj /F2 10 Tf (NamedTuples) Tj /F1 10 Tf ( from existing ) Tj /F2 10 Tf (NamedTuples) Tj /F1 10 Tf ( is simple:) Tj T* ET Q Q q 1 0 0 1 62.69291 417.4236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 72 re B* Q q BT 1 0 0 1 0 50 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( Point = NamedTuple\('Point', 'x y'\)) Tj T* (>) Tj (>) Tj (>) Tj ( Color = NamedTuple\('Color', 'r g b'\)) Tj T* (>) Tj (>) Tj (>) Tj ( Pixel = NamedTuple\('Pixel', Point+Color, module=__name__\)) Tj T* (>) Tj (>) Tj (>) Tj ( Pixel) Tj T* (<) Tj (NamedTuple 'Pixel') Tj (>) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 385.4236 cm q 0 0 0 rg BT 1 0 0 1 0 14 Tm /F1 10 Tf 12 TL .070514 Tw (The existing fields in the bases classes are renumbered to fit the new class, but keep their doc strings and) Tj T* 0 Tw (default values. If you use standard subclassing:) Tj T* ET Q Q q 1 0 0 1 62.69291 268.2236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 108 re B* Q q BT 1 0 0 1 0 86 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( Point = NamedTuple\('Point', 'x y'\)) Tj T* (>) Tj (>) Tj (>) Tj ( class Pixel\(Point\):) Tj T* (... r = 2, 'red component', 11) Tj T* (... g = 3, 'green component', 29) Tj T* (... b = 4, 'blue component', 37) Tj T* (...) Tj T* (>) Tj (>) Tj (>) Tj ( Pixel.__fields__) Tj T* (['x', 'y', 'r', 'g', 'b']) Tj T* ET Q Q Q Q Q q 1 0 0 1 62.69291 248.2236 cm q 0 0 0 rg BT 1 0 0 1 0 2 Tm /F1 10 Tf 12 TL (You must manage the numbering yourself.) Tj T* ET Q Q q 1 0 0 1 62.69291 215.2236 cm q BT 1 0 0 1 0 3.5 Tm 21 TL /F3 17.5 Tf 0 0 0 rg (Creating NamedConstants) Tj T* ET Q Q q 1 0 0 1 62.69291 197.2236 cm q BT 1 0 0 1 0 2 Tm 12 TL /F1 10 Tf 0 0 0 rg (A ) Tj /F2 10 Tf (NamedConstant) Tj /F1 10 Tf ( class is created much like an ) Tj /F2 10 Tf (Enum) Tj /F1 10 Tf (:) Tj T* ET Q Q q 1 0 0 1 62.69291 80.02362 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 108 re B* Q q BT 1 0 0 1 0 86 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj (>) Tj ( from aenum import NamedConstant) Tj T* (>) Tj (>) Tj (>) Tj ( class Konstant\(NamedConstant\):) Tj T* (... PI = 3.14159) Tj T* (... TAU = 2 * PI) Tj T* T* (>) Tj (>) Tj (>) Tj ( Konstant.PI) Tj T* (<) Tj (Konstant.PI: 3.14159) Tj (>) Tj T* T* ET Q Q Q Q Q endstream endobj 114 0 obj << /Length 702 >> stream 1 0 0 1 0 0 cm BT /F1 12 Tf 14.4 TL ET q 1 0 0 1 62.69291 607.8236 cm q q 1 0 0 1 0 0 cm q 1 0 0 1 6.6 6.6 cm q .662745 .662745 .662745 RG .5 w .960784 .960784 .862745 rg n -6 -6 468.6898 156 re B* Q q BT 1 0 0 1 0 134 Tm 12 TL /F2 10 Tf 0 0 0 rg (>) Tj (>) Tj ( print\(Konstant.PI\)) Tj T* (3.14159) Tj T* T* (>) Tj (>) Tj (>) Tj ( Konstant.PI = 'apple') Tj T* (Traceback \(most recent call last\):) Tj T* (...) Tj T* (AttributeError: cannot rebind constant ) Tj (<) Tj (Konstant.PI) Tj (>) Tj T* T* (>) Tj (>) Tj (>) Tj ( del Konstant.PI) Tj T* (Traceback \(most recent call last\):) Tj T* (...) Tj T* (AttributeError: cannot delete constant ) Tj (<) Tj (Konstant.PI) Tj (>) Tj T* ET Q Q Q Q Q endstream endobj 115 0 obj << /Nums [ 0 116 0 R 1 117 0 R 2 118 0 R 3 119 0 R 4 120 0 R 5 121 0 R 6 122 0 R 7 123 0 R 8 124 0 R 9 125 0 R 10 126 0 R 11 127 0 R 12 128 0 R 13 129 0 R 14 130 0 R 15 131 0 R 16 132 0 R 17 133 0 R 18 134 0 R 19 135 0 R 20 136 0 R 21 137 0 R 22 138 0 R 23 139 0 R 24 140 0 R 25 141 0 R 26 142 0 R 27 143 0 R ] >> endobj 116 0 obj << /S /D /St 1 >> endobj 117 0 obj << /S /D /St 2 >> endobj 118 0 obj << /S /D /St 3 >> endobj 119 0 obj << /S /D /St 4 >> endobj 120 0 obj << /S /D /St 5 >> endobj 121 0 obj << /S /D /St 6 >> endobj 122 0 obj << /S /D /St 7 >> endobj 123 0 obj << /S /D /St 8 >> endobj 124 0 obj << /S /D /St 9 >> endobj 125 0 obj << /S /D /St 10 >> endobj 126 0 obj << /S /D /St 11 >> endobj 127 0 obj << /S /D /St 12 >> endobj 128 0 obj << /S /D /St 13 >> endobj 129 0 obj << /S /D /St 14 >> endobj 130 0 obj << /S /D /St 15 >> endobj 131 0 obj << /S /D /St 16 >> endobj 132 0 obj << /S /D /St 17 >> endobj 133 0 obj << /S /D /St 18 >> endobj 134 0 obj << /S /D /St 19 >> endobj 135 0 obj << /S /D /St 20 >> endobj 136 0 obj << /S /D /St 21 >> endobj 137 0 obj << /S /D /St 22 >> endobj 138 0 obj << /S /D /St 23 >> endobj 139 0 obj << /S /D /St 24 >> endobj 140 0 obj << /S /D /St 25 >> endobj 141 0 obj << /S /D /St 26 >> endobj 142 0 obj << /S /D /St 27 >> endobj 143 0 obj << /S /D /St 28 >> endobj xref 0 144 0000000000 65535 f 0000000073 00000 n 0000000145 00000 n 0000000252 00000 n 0000000357 00000 n 0000000469 00000 n 0000000588 00000 n 0000000756 00000 n 0000000979 00000 n 0000001147 00000 n 0000001370 00000 n 0000001539 00000 n 0000001655 00000 n 0000001824 00000 n 0000002056 00000 n 0000002262 00000 n 0000002468 00000 n 0000002674 00000 n 0000002843 00000 n 0000003012 00000 n 0000003244 00000 n 0000003413 00000 n 0000003582 00000 n 0000003814 00000 n 0000003983 00000 n 0000004208 00000 n 0000004414 00000 n 0000004620 00000 n 0000004826 00000 n 0000005032 00000 n 0000005239 00000 n 0000005446 00000 n 0000005653 00000 n 0000005860 00000 n 0000006067 00000 n 0000006274 00000 n 0000006481 00000 n 0000006688 00000 n 0000006857 00000 n 0000007083 00000 n 0000007290 00000 n 0000007497 00000 n 0000007704 00000 n 0000007911 00000 n 0000008118 00000 n 0000008325 00000 n 0000008432 00000 n 0000008761 00000 n 0000008836 00000 n 0000008952 00000 n 0000009083 00000 n 0000009261 00000 n 0000009411 00000 n 0000009537 00000 n 0000009698 00000 n 0000009840 00000 n 0000009963 00000 n 0000010097 00000 n 0000010271 00000 n 0000010380 00000 n 0000010502 00000 n 0000010621 00000 n 0000010729 00000 n 0000010896 00000 n 0000011002 00000 n 0000011128 00000 n 0000011251 00000 n 0000011370 00000 n 0000011490 00000 n 0000011609 00000 n 0000011747 00000 n 0000011885 00000 n 0000012049 00000 n 0000012144 00000 n 0000012318 00000 n 0000012430 00000 n 0000012555 00000 n 0000012681 00000 n 0000012789 00000 n 0000012967 00000 n 0000013081 00000 n 0000013226 00000 n 0000013340 00000 n 0000013514 00000 n 0000013622 00000 n 0000013732 00000 n 0000013857 00000 n 0000014112 00000 n 0000019006 00000 n 0000024825 00000 n 0000030727 00000 n 0000034723 00000 n 0000040153 00000 n 0000043501 00000 n 0000047935 00000 n 0000052173 00000 n 0000056429 00000 n 0000061015 00000 n 0000065222 00000 n 0000069327 00000 n 0000073337 00000 n 0000080197 00000 n 0000084297 00000 n 0000087567 00000 n 0000091715 00000 n 0000095057 00000 n 0000098925 00000 n 0000102893 00000 n 0000105820 00000 n 0000111592 00000 n 0000115879 00000 n 0000120818 00000 n 0000123963 00000 n 0000127735 00000 n 0000131537 00000 n 0000132291 00000 n 0000132637 00000 n 0000132672 00000 n 0000132707 00000 n 0000132742 00000 n 0000132777 00000 n 0000132812 00000 n 0000132847 00000 n 0000132882 00000 n 0000132917 00000 n 0000132952 00000 n 0000132988 00000 n 0000133024 00000 n 0000133060 00000 n 0000133096 00000 n 0000133132 00000 n 0000133168 00000 n 0000133204 00000 n 0000133240 00000 n 0000133276 00000 n 0000133312 00000 n 0000133348 00000 n 0000133384 00000 n 0000133420 00000 n 0000133456 00000 n 0000133492 00000 n 0000133528 00000 n 0000133564 00000 n 0000133600 00000 n trailer << /ID [<0480a0ed05945e18dfdbcdd1622d7eb9><0480a0ed05945e18dfdbcdd1622d7eb9>] % ReportLab generated PDF document -- digest (http://www.reportlab.com) /Info 46 0 R /Root 45 0 R /Size 144 >> startxref 133636 %%EOF