Skip to content

Initial support for Python 3.5#2

Open
nocko wants to merge 1 commit into
escattone:masterfrom
nocko:python3
Open

Initial support for Python 3.5#2
nocko wants to merge 1 commit into
escattone:masterfrom
nocko:python3

Conversation

@nocko

@nocko nocko commented Oct 27, 2016

Copy link
Copy Markdown

No description provided.

@nocko

nocko commented Oct 27, 2016

Copy link
Copy Markdown
Author

1.0.2 doesn't pass pypy on my machine for the same reasons. IDK why the build passed a year ago. The python3.5 tests pass, but aren't run by your Travis setup.

@escattone

Copy link
Copy Markdown
Owner

Hey nocko! Sorry for my delayed response! Life has been hectic and I've been traveling for work for the past week. Thanks so much for your contribution! I have not been following Twisted for a while, so I was really pleasantly surprised to see how far along the port to Python 3 was. I'll take a look at this soon and get back to you. Thanks again!

@escattone escattone left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have two suggested changes so far.

Comment thread txpool/pool.py

def add(self, text):
lines = (self.remains + text).splitlines()
lines = (self.remains + text.decode('latin-1')).splitlines()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

text will be in bytes and is coming from the worker process' stderr (which is a different i/o channel than the one sending pickled results), and is most likely encoded as "utf-8" I believe (unless the worker process explicitly encodes its stderr as something else), so my thought is that text.decode() (using the default encoding of "utf-8") is better here.

Comment thread txpool/worker.py
out_safe.write('%d:%s,' % (len(pickled), pickled))
out_safe.write((u'{}:{},'.format(
len(pickled),
pickled.decode('latin-1'))).encode('latin-1'))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out_safe is already opened in binary mode, and I believe pickled is of type bytes, so I'd like to stay with bytes formatting (bytes only supports the % operator). This avoids decoding pickled into unicode for the formatting operation, and then encoding it again into bytes for the write. Also, I'd like to explicitly indicate bytes with the b prefix. I'm using %s instead of %b due to this code having to support Python 2 as well as Python 3.

out_safe.write(b'%d:%s,' % (len(pickled), pickled))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants