Part of the repository modernization effort.
Background
The package depends on six and on bmemcached/compat.py. Both exist only to support Python 2. The project targets Python 3 only. See the minimum-version issue.
bmemcached/compat.py gives three names: pickle, long, and unicode. On Python 3, long is int and unicode is str.
Inventory
six in runtime code
| Location |
Current code |
Change to |
setup.py:35 |
"six" in install_requires |
Remove the entry |
bmemcached/compat.py:1,9 |
import six, if six.PY3: |
Delete the file |
bmemcached/utils.py:1,16 |
six.binary_type, six.string_types |
bytes, str |
bmemcached/protocol.py:14-15 |
import six, from six import binary_type, text_type |
bytes, str. Delete the imports |
bmemcached/protocol.py:428 |
if six.PY3: branch and the Python 2 branch after it |
Keep return value.decode('utf8'). Delete the Python 2 branch |
bmemcached/client/mixin.py:1,68 |
import six, isinstance(servers, six.string_types) |
isinstance(servers, str) |
six in docstrings only
These sites hold no runtime code. Reword six.string_types to str and six.binary_type to bytes.
bmemcached/protocol.py:283,285,357,405,409,450,512,514,577,625,651,687,713,889,923,941,958,1051
bmemcached/client/mixin.py:14,16,104,153
bmemcached/client/replicating.py:71,110,210,319,357,416,438
bmemcached/client/distributed.py:128,152,176,232,258,277
six in tests
Five files hold this shim:
if six.PY3:
from unittest import mock
else:
import mock
Sites: test/test_auth.py:4,9-12, test/test_server_parsing.py:4,8-11, test/test_errors.py:4,9-12, test/test_compression.py:4,9-12, test/test_simple_functions.py:5,12-15.
Replace each shim with from unittest import mock.
six.assertCountEqual(self, ...) appears at test/test_simple_functions.py:37,46,117,127,137,250,565,637,647,657,694 and test/test_error_handling.py:151,157,214. Replace each call with self.assertCountEqual(...). unittest.TestCase holds this method since Python 3.2.
Remove import six from test/test_error_handling.py:4.
bmemcached/compat.py consumers
bmemcached/protocol.py:17 — from bmemcached.compat import long, pickle
bmemcached/client/mixin.py:4 — from bmemcached.compat import pickle
bmemcached/client/distributed.py:6 — from bmemcached.compat import pickle
test/test_simple_functions.py:10 — from bmemcached.compat import long, unicode
Replace each pickle import with import pickle. The cPickle fallback has no purpose on Python 3.
In test/test_simple_functions.py, replace long at lines 48, 55, 260, 262, 263, 710, 712, 713 with int. Replace unicode at line 43 with str.
Warning: keep wire compatibility for the long flag
bmemcached/protocol.py:95 declares 'long': 1 << 2 in FLAGS. Two branches use it.
The write branch at bmemcached/protocol.py:373-375 is already dead:
elif isinstance(value, long) and isinstance(value, bool) is False:
flags |= self.FLAGS['long']
compat.long is int on Python 3. The isinstance(value, int) check at lines 371-372 always matches first. Delete lines 373-375.
The read branch at bmemcached/protocol.py:421-422 must stay:
elif flags & FLAGS['long']:
return long(value)
An old client version can have written a value with this flag. Keep the branch. Change long(value) to int(value). Keep the FLAGS['long'] constant.
Acceptance criteria
Files to change
bmemcached/compat.py (delete), bmemcached/utils.py, bmemcached/protocol.py, bmemcached/client/mixin.py, bmemcached/client/replicating.py, bmemcached/client/distributed.py, setup.py, requirements_test.txt, test/test_auth.py, test/test_server_parsing.py, test/test_errors.py, test/test_compression.py, test/test_simple_functions.py, test/test_error_handling.py.
Order
Do the minimum-version issue first.
Part of the repository modernization effort.
Background
The package depends on
sixand onbmemcached/compat.py. Both exist only to support Python 2. The project targets Python 3 only. See the minimum-version issue.bmemcached/compat.pygives three names:pickle,long, andunicode. On Python 3,longisintandunicodeisstr.Inventory
sixin runtime codesetup.py:35"six"ininstall_requiresbmemcached/compat.py:1,9import six,if six.PY3:bmemcached/utils.py:1,16six.binary_type,six.string_typesbytes,strbmemcached/protocol.py:14-15import six,from six import binary_type, text_typebytes,str. Delete the importsbmemcached/protocol.py:428if six.PY3:branch and the Python 2 branch after itreturn value.decode('utf8'). Delete the Python 2 branchbmemcached/client/mixin.py:1,68import six,isinstance(servers, six.string_types)isinstance(servers, str)sixin docstrings onlyThese sites hold no runtime code. Reword
six.string_typestostrandsix.binary_typetobytes.bmemcached/protocol.py:283,285,357,405,409,450,512,514,577,625,651,687,713,889,923,941,958,1051bmemcached/client/mixin.py:14,16,104,153bmemcached/client/replicating.py:71,110,210,319,357,416,438bmemcached/client/distributed.py:128,152,176,232,258,277sixin testsFive files hold this shim:
Sites:
test/test_auth.py:4,9-12,test/test_server_parsing.py:4,8-11,test/test_errors.py:4,9-12,test/test_compression.py:4,9-12,test/test_simple_functions.py:5,12-15.Replace each shim with
from unittest import mock.six.assertCountEqual(self, ...)appears attest/test_simple_functions.py:37,46,117,127,137,250,565,637,647,657,694andtest/test_error_handling.py:151,157,214. Replace each call withself.assertCountEqual(...).unittest.TestCaseholds this method since Python 3.2.Remove
import sixfromtest/test_error_handling.py:4.bmemcached/compat.pyconsumersbmemcached/protocol.py:17—from bmemcached.compat import long, picklebmemcached/client/mixin.py:4—from bmemcached.compat import picklebmemcached/client/distributed.py:6—from bmemcached.compat import pickletest/test_simple_functions.py:10—from bmemcached.compat import long, unicodeReplace each
pickleimport withimport pickle. ThecPicklefallback has no purpose on Python 3.In
test/test_simple_functions.py, replacelongat lines 48, 55, 260, 262, 263, 710, 712, 713 withint. Replaceunicodeat line 43 withstr.Warning: keep wire compatibility for the
longflagbmemcached/protocol.py:95declares'long': 1 << 2inFLAGS. Two branches use it.The write branch at
bmemcached/protocol.py:373-375is already dead:compat.longisinton Python 3. Theisinstance(value, int)check at lines 371-372 always matches first. Delete lines 373-375.The read branch at
bmemcached/protocol.py:421-422must stay:An old client version can have written a value with this flag. Keep the branch. Change
long(value)toint(value). Keep theFLAGS['long']constant.Acceptance criteria
bmemcached/ortest/importssix.setup.pydropssixfrominstall_requires.bmemcached/compat.pyis deleted.bmemcached/protocol.py:373-375is deleted.bmemcached/protocol.py:421-422stays and callsint(value).FLAGS['long']stays inbmemcached/protocol.py:95.mockis removed fromrequirements_test.txt.python -m compileall -q bmemcached testpasses.memcachedbinary onPATH.Files to change
bmemcached/compat.py(delete),bmemcached/utils.py,bmemcached/protocol.py,bmemcached/client/mixin.py,bmemcached/client/replicating.py,bmemcached/client/distributed.py,setup.py,requirements_test.txt,test/test_auth.py,test/test_server_parsing.py,test/test_errors.py,test/test_compression.py,test/test_simple_functions.py,test/test_error_handling.py.Order
Do the minimum-version issue first.