| | 1 | The list of standard YAML tags and corresponding Python types. |
| | 2 | {{{ |
| | 3 | !!null '' # None |
| | 4 | !!bool 'yes' # bool |
| | 5 | !!int '3...' # int or long |
| | 6 | !!float '3.14...' # float |
| | 7 | !!binary '...base64...' # str |
| | 8 | !!timestamp 'YYYY-...' # datetime.datetime |
| | 9 | !!omap [ ... ] # list of pairs (note that key uniqueness is not checked) |
| | 10 | !!pairs [ ... ] # list of pairs |
| | 11 | !!set { ... } # set |
| | 12 | !!str '...' # str or unicode (ASCII scalars are converted to str) |
| | 13 | !!seq [ ... ] # list |
| | 14 | !!map { ... } # dict |
| | 15 | }}} |
| | 16 | |
| | 17 | The list of Python-specific YAML tags and corresponding Python types. |
| | 18 | Tags representing complex objects such as class instances are in a separate list. |
| | 19 | Note that in most cases there are two tags that represent the same Python type |
| | 20 | (e.g. {{{!!map}}} and {{{!!python/dict}}}). In such cases, standard YAML tags |
| | 21 | are prioritized, and Python-specific form is added for completeness. |
| | 22 | {{{ |
| | 23 | !!python/none '' # None |
| | 24 | !!python/bool 'True' # bool |
| | 25 | !!python/str '...' # str |
| | 26 | !!python/unicode '...' # unicode |
| | 27 | !!python/int '123...' # int |
| | 28 | !!python/long '123...' # long |
| | 29 | !!python/float '3.14...' # float |
| | 30 | !!python/complex '1+1j' # complex |
| | 31 | !!python/list [ ... ] # list |
| | 32 | !!python/tuple [ ... ] # tuple |
| | 33 | !!python/dict { ... } # dict |
| | 34 | }}} |
| | 35 | |
| | 36 | To represent class instances and other complex objects, the following tags are used. |
| | 37 | {{{ |
| | 38 | !!python/name:module.name # module.name (types, classes, and functions) |
| | 39 | !!python/module:module # module |
| | 40 | !!python/object:module.name # module.name instance with the specified attributes |
| | 41 | { ...attributes... } |
| | 42 | !!python/object/apply:module.name # reduce protocol |
| | 43 | args: [ ... arguments ... ] |
| | 44 | kwds: { ... keywords ... } |
| | 45 | state: ... state ... |
| | 46 | listitems: [ ... listitems ... ] |
| | 47 | dictitems: { ... dictitems ... } |
| | 48 | !!python/object/apply:module.name # short form of !!python/object/apply |
| | 49 | [ ... arguments ... ] |
| | 50 | !!python/object/new:module.name # reduce protocol (__new__) |
| | 51 | args: [ ... arguments ... ] |
| | 52 | kwds: { ... keywords ... } |
| | 53 | state: ... state ... |
| | 54 | listitems: [ ... listitems ... ] |
| | 55 | dictitems: { ... dictitems ... } |
| | 56 | !!python/object/new:module.name # short form of !!python/object/new |
| | 57 | [ ... arguments ... ] |
| | 58 | }}} |