Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pyyaml 3.13] TypeError while dumping lambda in Python 3 #222

Closed
NiklasRosenstein opened this issue Oct 25, 2018 · 3 comments
Closed

[pyyaml 3.13] TypeError while dumping lambda in Python 3 #222

NiklasRosenstein opened this issue Oct 25, 2018 · 3 comments
Labels

Comments

@NiklasRosenstein
Copy link

NiklasRosenstein commented Oct 25, 2018

import yaml
print(yaml.dump(lambda: None))

This fails with a TypeError in Python 3 (not in Python 2).

[...]
  File "/Users/nrosenstein/Projects/.venv/lib/python3.7/site-packages/yaml/emitter.py", line 228, in expect_document_root
    self.expect_node(root=True)
  File "/Users/nrosenstein/Projects/.venv/lib/python3.7/site-packages/yaml/emitter.py", line 242, in expect_node
    self.process_tag()
  File "/Users/nrosenstein/Projects/.venv/lib/python3.7/site-packages/yaml/emitter.py", line 489, in process_tag
    self.prepared_tag = self.prepare_tag(tag)
  File "/Users/nrosenstein/Projects/.venv/lib/python3.7/site-packages/yaml/emitter.py", line 607, in prepare_tag
    for ch in data:
TypeError: ord() expected string of length 1, but int found

For reference:

pyyaml/lib3/yaml/emitter.py

Lines 569 to 575 in a2d481b

else:
if start < end:
chunks.append(prefix[start:end])
start = end = end+1
data = ch.encode('utf-8')
for ch in data:
chunks.append('%%%02X' % ord(ch))

On a side note, I don't know how the line numbers don't match. I have PyYAML 3.13 installed and this references the commit on the 3.13 tag.

str.encode() returns a bytes object in Python 3, which in turn yields integers and no substrings when iterated over, leading ord() to fail.

@perlpunk
Copy link
Member

perlpunk commented Nov 5, 2018

Thanks, this should actually be fixed by #129

@fersarr
Copy link

fersarr commented Nov 7, 2018

We are being hit by this too. I guess this explains the issue https://stackoverflow.com/questions/19897209/troubleshooting-typeerror-ord-expected-string-of-length-1-but-int-found

Any estimates on when #129 will be merged?

@perlpunk
Copy link
Member

This was fixed in PyYAML 5.1 with #129

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants