Repository navigation
Remove the remaining Python 2 idioms #267
Description
Part of the repository modernization effort.
Background
The code holds Python 2 idioms outside of six and bmemcached/compat.py. Each one is dead on Python 3.
Work items
Dead import fallbacks
bmemcached/protocol.py:6-8:
try:
from urlparse import SplitResult # type: ignore[import-not-found]
except ImportError:
from urllib.parse import SplitResultReplace with from urllib.parse import SplitResult. This also removes a # type: ignore comment.
test/test_pickler.py:6-9:
try:
import cPickle as pickle
except ImportError:
import pickleReplace with import pickle.
Old-style super() calls
bmemcached/protocol.py:106—super(Protocol, self).__init__()bmemcached/client/distributed.py:17—super(DistributedClient, self).__init__(...)test/test_error_handling.py:15—super(_CacheProxy, self).__init__()
Change each call to super().__init__(...).
Redundant object base class
bmemcached/client/mixin.py:8—class ClientMixin(object):test/test_pickler.py:15,19—class PickleableThing(object):,class JsonPickler(object):
Drop the explicit (object) base.
Dead string prefixes and headers
docs/conf.py:1— the# -*- coding: utf-8 -*-header. UTF-8 is the default source encoding on Python 3.docs/conf.py:45,46,191,192,221,222,235,236—u'...'prefixes.test/test_simple_functions.py:77,78,246,247,406,436,593,594,686,687—u'...'prefixes.
Do not change
Do not convert logger.debug('...%s...', arg) calls to f-strings. Sites include bmemcached/protocol.py:302,454,471,593,595,964,980,992. The logging module formats these lazily. An f-string forces eager formatting even when the log level is off.
Not found in this repository
A scan found no basestring, no has_key, no iteritems, no except X, e:, and no from __future__ import. No work is needed for these.
Acceptance criteria
- No
try/except ImportErrorimport fallback stays inbmemcached/ortest/. - Every
super()call uses the zero-argument form. - No class declares an explicit
objectbase. - No
u'...'prefix and no coding header stays in the listed files. -
logger.debugcalls keep lazy%arguments. - Behavior does not change. The full test suite passes.
Files to change
bmemcached/protocol.py, bmemcached/client/mixin.py, bmemcached/client/distributed.py, test/test_pickler.py, test/test_error_handling.py, test/test_simple_functions.py, docs/conf.py.
Order
Do the six removal issue first. The two issues touch the same lines in bmemcached/protocol.py.
Activity
jaysonsantos commentedon Sep 8, 2026
Tracked in #277.
feat: set the Python 3.10 floor and remove the Python 2 support layer (…