This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
Python3 support #22
Closed
Closed
Python3 support #22
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d4b0491
Added Python3 to travis.
tricoder42 4a0b06f
Added Six compatability layer.
tricoder42 a8d95d2
Added Python3 support.
tricoder42 272af6f
Ported metaclass definition.
tricoder42 d2e3de2
Added documentation to import alias.
tricoder42 a0d966b
Use range iterator in Python 2.x
tricoder42 d873e1a
Remove unicode()
tricoder42 a43411d
Fixed typo.
tricoder42 0887bd0
_pickle should return str/bytes.
tricoder42 db83618
Cleanup.
tricoder42 8cbad1c
Add basestring alias for PY3.
tricoder42 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
language: python | ||
python: | ||
- "2.7" | ||
- "3.2" | ||
- "3.3" | ||
script: python -m unittest discover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
|
||
import collections | ||
import six | ||
|
||
from .base import RedisCollection, same_types | ||
|
||
|
@@ -366,7 +367,7 @@ def __init__(self, *args, **kwargs): | |
super(Counter, self).__init__(*args, **kwargs) | ||
|
||
def _pickle(self, data): | ||
return unicode(int(data)) | ||
return int(data) | ||
|
||
def _unpickle(self, string): | ||
if string is None: | ||
|
@@ -378,7 +379,7 @@ def _obj_to_data(self, obj): | |
is_mapping = isinstance(obj, collections.Mapping) | ||
|
||
data = obj._data() if is_redis else obj | ||
return dict(data) if is_mapping else iter(data) | ||
return dict(data) if is_mapping else map(six.b, data) | ||
|
||
def getmany(self, *keys): | ||
values = super(Counter, self).getmany(*keys) | ||
|
@@ -401,7 +402,7 @@ def elements(self): | |
""" | ||
for element, count in self._data(): | ||
if count: | ||
for _ in xrange(0, count): | ||
for _ in range(0, count): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But range in Python 2.X is not the same as range in Python 3.X, isn't it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right. I wasn't precise enough :) There's fix in a0d966b |
||
yield element | ||
|
||
def _update(self, data, pipe=None): | ||
|
@@ -457,7 +458,6 @@ def op_trans(pipe): | |
|
||
c1 = collections.Counter(d1) | ||
result = fn(c1, d2) | ||
|
||
if update: | ||
result = c1 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
redis | ||
six |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder what is purpose of this line. Test suite passes even with identity function (
return data
). Why you convertdata
to int and then to unicode? I'm asking because my "fix" isn't precise either.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is type check (
int
) and serialization (unicode
). In this implementation ofCounter
, data has to be integer only and then they are serialized for Redis just by callingunicode
. Maybe it involves some redundancy, but it is improving readability and consistency. I agree coercing toint
is stupid "validation", but it did the job quite well so far.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not sure. If
int
is called as type check only, it would work. There's nounicode
in Py3 and "it works" even without it. I'll try to fix it so it reflects original behavior.Edit: Added d873e1a