TypeError raised from ord() call in yaml.emit

Open Beginner friendly
#862 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
66/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
backend

Research direction

Read emitter.py at prepare_tag_prefix around line 575, then run the supplied BytesIO reproducer through yaml.parse and yaml.emit. Done means this input emits without the TypeError, with a regression check covering the reported case.

Written by the indexing model from the issue text.

Description

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
Dominant language
Python
Stars
2.9k
Forks
607
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from yaml/pyyaml

All issues in yaml/pyyaml

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.