Skip to content

Add Python 3 support#62

Merged
chekunkov merged 3 commits intomasterfrom
py3
May 4, 2016
Merged

Add Python 3 support#62
chekunkov merged 3 commits intomasterfrom
py3

Conversation

@bertinatto
Copy link
Contributor

Do we want to support py3[0-2]?

If we do want to support this version range we have to go over all string literals and use six.u instead of the u prefix literal. I'm avoiding using unicode_literals.

@chekunkov
Copy link
Contributor

Do we want to support py3[0-2]?

don't think so, Python>=3.3 is fine

I'm avoiding using unicode_literals.

why?

@bertinatto
Copy link
Contributor Author

@chekunkov, I see 2 main reasons: first because we lose the option to specify a native string literal (or at least it is most more cumbersome [1]). It may be useful in the future.

Also, unicode_literals converts docstrings to unicode, crushing Pydoc in some cases (again, we may want to use it in the future :) ).

Armin Ronacher (flask) started a nice discussion about unicode_literals in this thread [2].

[1] http://python-future.org/unicode_literals.html#drawbacks
[2] PythonCharmers/python-future#22

@chekunkov
Copy link
Contributor

I see, thanks @bertinatto

def _encode_identity(iter):
data = StringIO()
data = BytesIO()
for item in iter:
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry for nitpicking, but can we replace iter with something like iterable here - I don't like when builtins are shadowed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Done.

I handled it in another commit because it was already there before this PR.

@bertinatto bertinatto changed the title [WIP] Add Python 3 support Add Python 3 support Mar 31, 2016
import random
import logging
import warnings
import six
Copy link
Contributor

Choose a reason for hiding this comment

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

please add six to requirements and setup.py

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this.

Added six and rebased against master. #64 allowed to catch 2 more issues.

elif not isinstance(p, str):
p = str(p)
elif not isinstance(p, six.text_type):
p = six.u(str(p))
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be simply six.text_type(p)

@bertinatto bertinatto force-pushed the py3 branch 3 times, most recently from d5365a8 to cece266 Compare April 22, 2016 17:56
'Value exceeds max encoded size of 1048576 bytes:'
' \'{"b+\\.\\.\\.\'',
w.write, {'b'*(m/2): 'x'*(m/2)})
w.write, {'b'*int(m/2): 'x'*int(m/2)})
Copy link
Contributor

Choose a reason for hiding this comment

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

This is better expressed as floordiv, m // 2.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

also PEP8 suggests spaces between operands, i.e. {'b' * (m // 2): 'x' * (m // 2)}

Copy link
Contributor

Choose a reason for hiding this comment

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

to be fair, they are not necessary: https://www.python.org/dev/peps/pep-0008/#other-recommendations

pep8 requires one space around comparisons, boolean operators and assignments. other operators are required to have no more than one space and the same amount on both sides. also, quite a shocker for me from No section:

No:

x = x * 2 - 1
hypot2 = x * x + y * y
c = (a + b) * (a - b)

Copy link
Contributor

@chekunkov chekunkov Apr 28, 2016

Choose a reason for hiding this comment

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

interesting, I was taught to do this differently :) and linters usually show an error for such formatting. I don't have a strong opinion here, "Use your own judgment" can be applied.

also, quite a shocker for me from No section

haha, yeah, I thought I knew PEP8. I was wrong :)

@immerrr
Copy link
Contributor

immerrr commented Apr 27, 2016

Added couple nitpicks, but all in all seems nice. Do we want to enforce absolute imports with from __future__ import absolute_import?

self.apipost(jl=self._data, is_idempotent=True)
else:
self.apipost(jl=dict((k, v) for k, v in self._data.iteritems()
self.apipost(jl=dict((k, v) for k, v in six.iteritems(self._data)
Copy link
Contributor

Choose a reason for hiding this comment

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

what about updating the python idioms: {k: v for k, v in ... }

@chekunkov
Copy link
Contributor

Do we want to enforce absolute imports with from future import absolute_import

no objections

@bertinatto bertinatto force-pushed the py3 branch 2 times, most recently from ad80a76 to 9a5c80a Compare May 1, 2016 12:32
@bertinatto
Copy link
Contributor Author

Do we want to enforce absolute imports with from future import absolute_import

May I question the use of from future import absolute_import? Do you think it's really necessary?

I don't see a lot of advantages using it, since Python 3 tests will catch the use of non-absolute imports. Also, I see it's not enforced in other py3-compatible libraries.

What do you think?

@immerrr
Copy link
Contributor

immerrr commented May 2, 2016

Do you think it [absolute import]'s really necessary?

No, this is why it was a question :) Ok, it would only affect intra-hubstorage import, we have control over it in tests, let's not do that.

@chekunkov chekunkov merged commit b962ec6 into master May 4, 2016
@chekunkov chekunkov deleted the py3 branch May 4, 2016 13:30
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.

4 participants