pyyaml
pyyaml copied to clipboard
TypeError raised from ord() call in yaml.emit
trafficstars
The below code results in a TypeError: ord() expected string of length 1, but int found when yaml.emit is called. This occurs in the function prepare_tag_prefix at line 575 in emitter.py.
Minimized Reproducer:
import io
import yaml
text = io.BytesIO( b"%TAG ! tag:%002:\n---")
events = list(yaml.parse(text))
output = yaml.emit(events)
Version Information:
7.0.0.dev0
also occurs in the current release: 6.0.2
Exception Trace:
File "/rep.py", line 6, in <module>
output = yaml.emit(events)
File "lib/python3.9/site-packages/yaml/__init__.py", line 172, in emit
dumper.emit(event)
File "lib/python3.9/site-packages/yaml/emitter.py", line 115, in emit
self.state()
File "lib/python3.9/site-packages/yaml/emitter.py", line 176, in expect_first_document_start
return self.expect_document_start(first=True)
File "lib/python3.9/site-packages/yaml/emitter.py", line 193, in expect_document_start
prefix_text = self.prepare_tag_prefix(prefix)
File "lib/python3.9/site-packages/yaml/emitter.py", line 575, in prepare_tag_prefix
chunks.append('%%%02X' % ord(ch))
TypeError: ord() expected string of length 1, but int found