Skip to content

Commit

Permalink
README: update repr_unknown example to name values consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-fg committed Dec 11, 2024
1 parent dbe04d4 commit 09eda7f
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,13 @@ Features and Tricks

* Dump any non-YAML-type values when debugging or to replace later::

>>> unknown1 = type('test2', (object,), dict(a='b'))()
>>> unknown2 = type('test2', (object,), dict(__repr__=lambda s: '# test2 repr'+' '*80))()
>>> data = dict(known='test1', unknown1=unknown1, unknown2=unknown2)
>>> pyaml.p(data, repr_unknown=True)

known: test1
unknown1: <__main__.test2 object at 0x7fb19d8a8c80> # python value
unknown2: '# test2 repr ...[50/92]' # python __main__.test2
>>> test2 = type('test2', (object,), dict(a='b'))()
>>> test3 = type('test3', (object,), dict(__repr__=lambda s: '# test3 repr'+' '*80))()
>>> pyaml.p(dict(test1='test1', test2=test2, test3=test3), repr_unknown=True)

test1: test1
test2: <__main__.test2 object at 0x7f00ccd1ade0> # python value
test3: '# test3 repr ...[50/92]' # python __main__.test3

Such unknown-type values get truncated if their repr() is too long, which can
be controlled by passing int max-length to repr_unknown instead of bool.
Expand Down

0 comments on commit 09eda7f

Please sign in to comment.