Re:“Python's batteries are leaking”
by jteppinette on Saturday May 18, 2019 @03:14PM
(#19949190)
No compatibility layer. Its really not bad.
there are a few modules that are simply at different locations but have the same API
if PY3:
from http import client as httplib
else:
import httplib
constants PY3 = sys.version_info >= (3, 0)
PY2 = sys.version_info < (3, 0)
PY26 = sys.version_info >= (2, 6) and sys.version_info < (2, 7)
is string isinstance(<maybe_string>, basestring if PY2 else str)
using different classes # Python 2.6 doesn't properly UTF-8 encode syslog messages, so it needs
# to be performed in a custom formatter.
formatter_class = UnicodeLoggingFormatter if PY26 else logging.FormatterYou don't need all of six in most cases. You just need a couple of different functions.
As the maintainer of WebOb/Pyramid/Waitress we have a compat module that contains all of the changes/renames/functions to help with the Python2/3 compatibility and all tests run across both platforms.
Are the functions borrowed heavily from six? Yes, but we don't need to vendor all of six.
fwiw, six can easily be vendored into a project to avoid the technical external dependency. that is how we manage it for kafka-python.