diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ca07afa0..8e590e8a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,14 +12,11 @@ jobs: os: - ubuntu-latest python-version: - - 2.7 - - 3.5 - 3.6 - 3.7 - 3.8 - 3.9 - - 3.10-dev - - pypy-2.7 + - "3.10" - pypy-3.6 - pypy-3.7 steps: @@ -49,14 +46,11 @@ jobs: os: - macos-latest python-version: - - 2.7 - - 3.5 - 3.6 - 3.7 - 3.8 - 3.9 - - 3.10-dev - - pypy-2.7 + - "3.10" - pypy-3.6 - pypy-3.7 steps: @@ -86,13 +80,11 @@ jobs: os: - windows-latest python-version: - - 3.5 - 3.6 - 3.7 - 3.8 - 3.9 - - 3.10-dev - - pypy-2.7 + - "3.10" - pypy-3.6 - pypy-3.7 steps: diff --git a/docs/changes.rst b/docs/changes.rst index fcc88a4c..d2897c5e 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -1,6 +1,14 @@ Release Notes ============= +Version 1.14.0 +-------------- + +**Bugs Fixed** + +* Drop support for Python 2.7 and 3.5, which are past their end of lifetime. + + Version 1.13.1 -------------- diff --git a/setup.cfg b/setup.cfg index 84351281..760faafa 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,10 +16,7 @@ keywords = wrapper, proxy, decorator classifiers = Development Status :: 5 - Production/Stable License :: OSI Approved :: BSD License - Programming Language :: Python :: 2 - Programming Language :: Python :: 2.7 Programming Language :: Python :: 3 - Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 @@ -34,7 +31,7 @@ project_urls = [options] zip_safe = false -python_requires = >= 2.7, != 3.0.*, != 3.1.*, != 3.2.*, != 3.3.*, != 3.4.* +python_requires = >= 3.6 packages = find: package_dir = =src @@ -71,19 +68,16 @@ norecursedirs = .tox venv [tox:tox] envlist = - py{27,35,36,37,38,39,310}-{without,install,disable}-extensions, + py{36,37,38,39,310}-{without,install,disable}-extensions, pypy-without-extensions [gh-actions] python = - 2.7: py27, py27-without-extensions, py27-install-extensions, py27-disable-extensions - 3.5: py35, py35-without-extensions, py35-install-extensions, py35-disable-extensions 3.6: py36, py36-without-extensions, py36-install-extensions, py36-disable-extensions 3.7: py37, py37-without-extensions, py37-install-extensions, py37-disable-extensions 3.8: py38, py38-without-extensions, py38-install-extensions, py38-disable-extensions 3.9: py39, py39-without-extensions, py39-install-extensions, py39-disable-extensions 3.10: py310, py310-without-extensions, py310-install-extensions, py310-disable-extensions - pypy-2.7: pypy-without-extensions pypy-3.6: pypy-without-extensions pypy-3.7: pypy-without-extensions diff --git a/src/wrapt/__init__.py b/src/wrapt/__init__.py index 7f32285f..8bba9cc2 100644 --- a/src/wrapt/__init__.py +++ b/src/wrapt/__init__.py @@ -1,4 +1,4 @@ -__version_info__ = ('1', '13', '1') +__version_info__ = ('1', '14', '0') __version__ = '.'.join(__version_info__) from .wrappers import (ObjectProxy, CallableObjectProxy, FunctionWrapper, diff --git a/src/wrapt/_wrappers.c b/src/wrapt/_wrappers.c index b677fff6..0a2e8bf0 100644 --- a/src/wrapt/_wrappers.c +++ b/src/wrapt/_wrappers.c @@ -78,19 +78,11 @@ static int WraptObjectProxy_raw_init(WraptObjectProxyObject *self, self->wrapped = wrapped; if (!module_str) { -#if PY_MAJOR_VERSION >= 3 module_str = PyUnicode_InternFromString("__module__"); -#else - module_str = PyString_InternFromString("__module__"); -#endif } if (!doc_str) { -#if PY_MAJOR_VERSION >= 3 doc_str = PyUnicode_InternFromString("__doc__"); -#else - doc_str = PyString_InternFromString("__doc__"); -#endif } object = PyObject_GetAttr(wrapped, module_str); @@ -181,23 +173,13 @@ static PyObject *WraptObjectProxy_repr(WraptObjectProxyObject *self) return NULL; } -#if PY_MAJOR_VERSION >= 3 return PyUnicode_FromFormat("<%s at %p for %s at %p>", Py_TYPE(self)->tp_name, self, Py_TYPE(self->wrapped)->tp_name, self->wrapped); -#else - return PyString_FromFormat("<%s at %p for %s at %p>", - Py_TYPE(self)->tp_name, self, - Py_TYPE(self->wrapped)->tp_name, self->wrapped); -#endif } /* ------------------------------------------------------------------------- */ -#if PY_MAJOR_VERSION < 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 3) -typedef long Py_hash_t; -#endif - static Py_hash_t WraptObjectProxy_hash(WraptObjectProxyObject *self) { if (!self->wrapped) { @@ -298,33 +280,6 @@ static PyObject *WraptObjectProxy_multiply(PyObject *o1, PyObject *o2) /* ------------------------------------------------------------------------- */ -#if PY_MAJOR_VERSION < 3 -static PyObject *WraptObjectProxy_divide(PyObject *o1, PyObject *o2) -{ - if (PyObject_IsInstance(o1, (PyObject *)&WraptObjectProxy_Type)) { - if (!((WraptObjectProxyObject *)o1)->wrapped) { - PyErr_SetString(PyExc_ValueError, "wrapper has not been initialized"); - return NULL; - } - - o1 = ((WraptObjectProxyObject *)o1)->wrapped; - } - - if (PyObject_IsInstance(o2, (PyObject *)&WraptObjectProxy_Type)) { - if (!((WraptObjectProxyObject *)o2)->wrapped) { - PyErr_SetString(PyExc_ValueError, "wrapper has not been initialized"); - return NULL; - } - - o2 = ((WraptObjectProxyObject *)o2)->wrapped; - } - - return PyNumber_Divide(o1, o2); -} -#endif - -/* ------------------------------------------------------------------------- */ - static PyObject *WraptObjectProxy_remainder(PyObject *o1, PyObject *o2) { if (PyObject_IsInstance(o1, (PyObject *)&WraptObjectProxy_Type)) { @@ -586,20 +541,6 @@ static PyObject *WraptObjectProxy_or(PyObject *o1, PyObject *o2) /* ------------------------------------------------------------------------- */ -#if PY_MAJOR_VERSION < 3 -static PyObject *WraptObjectProxy_int(WraptObjectProxyObject *self) -{ - if (!self->wrapped) { - PyErr_SetString(PyExc_ValueError, "wrapper has not been initialized"); - return NULL; - } - - return PyNumber_Int(self->wrapped); -} -#endif - -/* ------------------------------------------------------------------------- */ - static PyObject *WraptObjectProxy_long(WraptObjectProxyObject *self) { if (!self->wrapped) { @@ -624,52 +565,6 @@ static PyObject *WraptObjectProxy_float(WraptObjectProxyObject *self) /* ------------------------------------------------------------------------- */ -#if PY_MAJOR_VERSION < 3 -static PyObject *WraptObjectProxy_oct(WraptObjectProxyObject *self) -{ - PyNumberMethods *nb; - - if (!self->wrapped) { - PyErr_SetString(PyExc_ValueError, "wrapper has not been initialized"); - return NULL; - } - - if ((nb = self->wrapped->ob_type->tp_as_number) == NULL || - nb->nb_oct == NULL) { - PyErr_SetString(PyExc_TypeError, - "oct() argument can't be converted to oct"); - return NULL; - } - - return (*nb->nb_oct)(self->wrapped); -} -#endif - -/* ------------------------------------------------------------------------- */ - -#if PY_MAJOR_VERSION < 3 -static PyObject *WraptObjectProxy_hex(WraptObjectProxyObject *self) -{ - PyNumberMethods *nb; - - if (!self->wrapped) { - PyErr_SetString(PyExc_ValueError, "wrapper has not been initialized"); - return NULL; - } - - if ((nb = self->wrapped->ob_type->tp_as_number) == NULL || - nb->nb_hex == NULL) { - PyErr_SetString(PyExc_TypeError, - "hex() argument can't be converted to hex"); - return NULL; - } - - return (*nb->nb_hex)(self->wrapped); -} -#endif - -/* ------------------------------------------------------------------------- */ - static PyObject *WraptObjectProxy_inplace_add(WraptObjectProxyObject *self, PyObject *other) { @@ -751,35 +646,6 @@ static PyObject *WraptObjectProxy_inplace_multiply( /* ------------------------------------------------------------------------- */ -#if PY_MAJOR_VERSION < 3 -static PyObject *WraptObjectProxy_inplace_divide( - WraptObjectProxyObject *self, PyObject *other) -{ - PyObject *object = NULL; - - if (!self->wrapped) { - PyErr_SetString(PyExc_ValueError, "wrapper has not been initialized"); - return NULL; - } - - if (PyObject_IsInstance(other, (PyObject *)&WraptObjectProxy_Type)) - other = ((WraptObjectProxyObject *)other)->wrapped; - - object = PyNumber_InPlaceDivide(self->wrapped, other); - - if (!object) - return NULL; - - Py_DECREF(self->wrapped); - self->wrapped = object; - - Py_INCREF(self); - return (PyObject *)self; -} -#endif - -/* ------------------------------------------------------------------------- */ - static PyObject *WraptObjectProxy_inplace_remainder( WraptObjectProxyObject *self, PyObject *other) { @@ -1273,7 +1139,6 @@ static PyObject *WraptObjectProxy_reversed( /* ------------------------------------------------------------------------- */ -#if PY_MAJOR_VERSION >= 3 static PyObject *WraptObjectProxy_round( WraptObjectProxyObject *self, PyObject *args) { @@ -1310,7 +1175,6 @@ static PyObject *WraptObjectProxy_round( return result; } -#endif /* ------------------------------------------------------------------------- */ @@ -1538,11 +1402,7 @@ static PyObject *WraptObjectProxy_getattro( PyErr_Clear(); if (!getattr_str) { -#if PY_MAJOR_VERSION >= 3 getattr_str = PyUnicode_InternFromString("__getattr__"); -#else - getattr_str = PyString_InternFromString("__getattr__"); -#endif } object = PyObject_GenericGetAttr((PyObject *)self, getattr_str); @@ -1564,13 +1424,8 @@ static PyObject *WraptObjectProxy_getattr( { PyObject *name = NULL; -#if PY_MAJOR_VERSION >= 3 if (!PyArg_ParseTuple(args, "U:__getattr__", &name)) return NULL; -#else - if (!PyArg_ParseTuple(args, "S:__getattr__", &name)) - return NULL; -#endif if (!self->wrapped) { PyErr_SetString(PyExc_ValueError, "wrapper has not been initialized"); @@ -1592,19 +1447,11 @@ static int WraptObjectProxy_setattro( PyObject *match = NULL; if (!startswith_str) { -#if PY_MAJOR_VERSION >= 3 startswith_str = PyUnicode_InternFromString("startswith"); -#else - startswith_str = PyString_InternFromString("startswith"); -#endif } if (!self_str) { -#if PY_MAJOR_VERSION >= 3 self_str = PyUnicode_InternFromString("_self_"); -#else - self_str = PyString_InternFromString("_self_"); -#endif } match = PyObject_CallMethodObjArgs(name, startswith_str, self_str, NULL); @@ -1620,11 +1467,7 @@ static int WraptObjectProxy_setattro( Py_XDECREF(match); if (!wrapped_str) { -#if PY_MAJOR_VERSION >= 3 wrapped_str = PyUnicode_InternFromString("__wrapped__"); -#else - wrapped_str = PyString_InternFromString("__wrapped__"); -#endif } if (PyObject_HasAttr((PyObject *)Py_TYPE(self), name)) @@ -1669,9 +1512,7 @@ static PyNumberMethods WraptObjectProxy_as_number = { (binaryfunc)WraptObjectProxy_add, /*nb_add*/ (binaryfunc)WraptObjectProxy_subtract, /*nb_subtract*/ (binaryfunc)WraptObjectProxy_multiply, /*nb_multiply*/ -#if PY_MAJOR_VERSION < 3 - (binaryfunc)WraptObjectProxy_divide, /*nb_divide*/ -#endif + (binaryfunc)WraptObjectProxy_remainder, /*nb_remainder*/ (binaryfunc)WraptObjectProxy_divmod, /*nb_divmod*/ (ternaryfunc)WraptObjectProxy_power, /*nb_power*/ @@ -1685,27 +1526,12 @@ static PyNumberMethods WraptObjectProxy_as_number = { (binaryfunc)WraptObjectProxy_and, /*nb_and*/ (binaryfunc)WraptObjectProxy_xor, /*nb_xor*/ (binaryfunc)WraptObjectProxy_or, /*nb_or*/ -#if PY_MAJOR_VERSION < 3 - 0, /*nb_coerce*/ -#endif -#if PY_MAJOR_VERSION < 3 - (unaryfunc)WraptObjectProxy_int, /*nb_int*/ - (unaryfunc)WraptObjectProxy_long, /*nb_long*/ -#else (unaryfunc)WraptObjectProxy_long, /*nb_int*/ 0, /*nb_long/nb_reserved*/ -#endif (unaryfunc)WraptObjectProxy_float, /*nb_float*/ -#if PY_MAJOR_VERSION < 3 - (unaryfunc)WraptObjectProxy_oct, /*nb_oct*/ - (unaryfunc)WraptObjectProxy_hex, /*nb_hex*/ -#endif (binaryfunc)WraptObjectProxy_inplace_add, /*nb_inplace_add*/ (binaryfunc)WraptObjectProxy_inplace_subtract, /*nb_inplace_subtract*/ (binaryfunc)WraptObjectProxy_inplace_multiply, /*nb_inplace_multiply*/ -#if PY_MAJOR_VERSION < 3 - (binaryfunc)WraptObjectProxy_inplace_divide, /*nb_inplace_divide*/ -#endif (binaryfunc)WraptObjectProxy_inplace_remainder, /*nb_inplace_remainder*/ (ternaryfunc)WraptObjectProxy_inplace_power, /*nb_inplace_power*/ (binaryfunc)WraptObjectProxy_inplace_lshift, /*nb_inplace_lshift*/ @@ -1755,9 +1581,7 @@ static PyMethodDef WraptObjectProxy_methods[] = { METH_VARARGS , 0 }, { "__bytes__", (PyCFunction)WraptObjectProxy_bytes, METH_NOARGS, 0 }, { "__reversed__", (PyCFunction)WraptObjectProxy_reversed, METH_NOARGS, 0 }, -#if PY_MAJOR_VERSION >= 3 { "__round__", (PyCFunction)WraptObjectProxy_round, METH_NOARGS, 0 }, -#endif { "__complex__", (PyCFunction)WraptObjectProxy_complex, METH_NOARGS, 0 }, #if PY_MAJOR_VERSION > 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 7) { "__mro_entries__", (PyCFunction)WraptObjectProxy_mro_entries, @@ -1805,13 +1629,8 @@ PyTypeObject WraptObjectProxy_Type = { (getattrofunc)WraptObjectProxy_getattro, /*tp_getattro*/ (setattrofunc)WraptObjectProxy_setattro, /*tp_setattro*/ 0, /*tp_as_buffer*/ -#if PY_MAJOR_VERSION < 3 - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | - Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ -#else Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ -#endif 0, /*tp_doc*/ (traverseproc)WraptObjectProxy_traverse, /*tp_traverse*/ (inquiry)WraptObjectProxy_clear, /*tp_clear*/ @@ -1878,11 +1697,7 @@ PyTypeObject WraptCallableObjectProxy_Type = { 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ -#if PY_MAJOR_VERSION < 3 - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ -#else Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ -#endif 0, /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ @@ -2122,13 +1937,8 @@ PyTypeObject WraptPartialCallableObjectProxy_Type = { 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ -#if PY_MAJOR_VERSION < 3 - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | - Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ -#else Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ -#endif 0, /*tp_doc*/ (traverseproc)WraptPartialCallableObjectProxy_traverse, /*tp_traverse*/ (inquiry)WraptPartialCallableObjectProxy_clear, /*tp_clear*/ @@ -2227,11 +2037,7 @@ static int WraptFunctionWrapperBase_init(WraptFunctionWrapperObject *self, "enabled", "binding", "parent", NULL }; if (!function_str) { -#if PY_MAJOR_VERSION >= 3 function_str = PyUnicode_InternFromString("function"); -#else - function_str = PyString_InternFromString("function"); -#endif } if (!PyArg_ParseTupleAndKeywords(args, kwds, @@ -2302,13 +2108,8 @@ static PyObject *WraptFunctionWrapperBase_call( static PyObject *classmethod_str = NULL; if (!function_str) { -#if PY_MAJOR_VERSION >= 3 function_str = PyUnicode_InternFromString("function"); classmethod_str = PyUnicode_InternFromString("classmethod"); -#else - function_str = PyString_InternFromString("function"); - classmethod_str = PyString_InternFromString("classmethod"); -#endif } if (self->enabled != Py_None) { @@ -2383,38 +2184,20 @@ static PyObject *WraptFunctionWrapperBase_descr_get( static PyObject *function_str = NULL; if (!bound_type_str) { -#if PY_MAJOR_VERSION >= 3 bound_type_str = PyUnicode_InternFromString( "__bound_function_wrapper__"); -#else - bound_type_str = PyString_InternFromString( - "__bound_function_wrapper__"); -#endif } if (!function_str) { -#if PY_MAJOR_VERSION >= 3 function_str = PyUnicode_InternFromString("function"); -#else - function_str = PyString_InternFromString("function"); -#endif } if (self->parent == Py_None) { -#if PY_MAJOR_VERSION < 3 - if (PyObject_IsInstance(self->object_proxy.wrapped, - (PyObject *)&PyClass_Type) || PyObject_IsInstance( - self->object_proxy.wrapped, (PyObject *)&PyType_Type)) { - Py_INCREF(self); - return (PyObject *)self; - } -#else if (PyObject_IsInstance(self->object_proxy.wrapped, (PyObject *)&PyType_Type)) { Py_INCREF(self); return (PyObject *)self; } -#endif if (Py_TYPE(self->object_proxy.wrapped)->tp_descr_get == NULL) { PyErr_Format(PyExc_AttributeError, @@ -2460,11 +2243,7 @@ static PyObject *WraptFunctionWrapperBase_descr_get( static PyObject *wrapped_str = NULL; if (!wrapped_str) { -#if PY_MAJOR_VERSION >= 3 wrapped_str = PyUnicode_InternFromString("__wrapped__"); -#else - wrapped_str = PyString_InternFromString("__wrapped__"); -#endif } wrapped = PyObject_GetAttr(self->parent, wrapped_str); @@ -2702,13 +2481,8 @@ PyTypeObject WraptFunctionWrapperBase_Type = { 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ -#if PY_MAJOR_VERSION < 3 - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | - Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ -#else Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ -#endif 0, /*tp_doc*/ (traverseproc)WraptFunctionWrapperBase_traverse, /*tp_traverse*/ (inquiry)WraptFunctionWrapperBase_clear, /*tp_clear*/ @@ -2768,11 +2542,7 @@ static PyObject *WraptBoundFunctionWrapper_call( } if (!function_str) { -#if PY_MAJOR_VERSION >= 3 function_str = PyUnicode_InternFromString("function"); -#else - function_str = PyString_InternFromString("function"); -#endif } /* @@ -2914,11 +2684,7 @@ PyTypeObject WraptBoundFunctionWrapper_Type = { 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ -#if PY_MAJOR_VERSION < 3 - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ -#else Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ -#endif 0, /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ @@ -2966,27 +2732,15 @@ static int WraptFunctionWrapper_init(WraptFunctionWrapperObject *self, } if (!classmethod_str) { -#if PY_MAJOR_VERSION >= 3 classmethod_str = PyUnicode_InternFromString("classmethod"); -#else - classmethod_str = PyString_InternFromString("classmethod"); -#endif } if (!staticmethod_str) { -#if PY_MAJOR_VERSION >= 3 staticmethod_str = PyUnicode_InternFromString("staticmethod"); -#else - staticmethod_str = PyString_InternFromString("staticmethod"); -#endif } if (!function_str) { -#if PY_MAJOR_VERSION >= 3 function_str = PyUnicode_InternFromString("function"); -#else - function_str = PyString_InternFromString("function"); -#endif } if (PyObject_IsInstance(wrapped, (PyObject *)&PyClassMethod_Type)) { @@ -2996,16 +2750,9 @@ static int WraptFunctionWrapper_init(WraptFunctionWrapperObject *self, binding = staticmethod_str; } else if ((instance = PyObject_GetAttrString(wrapped, "__self__")) != 0) { -#if PY_MAJOR_VERSION < 3 - if (PyObject_IsInstance(instance, (PyObject *)&PyClass_Type) || - PyObject_IsInstance(instance, (PyObject *)&PyType_Type)) { - binding = classmethod_str; - } -#else if (PyObject_IsInstance(instance, (PyObject *)&PyType_Type)) { binding = classmethod_str; } -#endif else binding = function_str; @@ -3054,11 +2801,7 @@ PyTypeObject WraptFunctionWrapper_Type = { 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ -#if PY_MAJOR_VERSION < 3 - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ -#else Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ -#endif 0, /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ @@ -3083,7 +2826,6 @@ PyTypeObject WraptFunctionWrapper_Type = { /* ------------------------------------------------------------------------- */ -#if PY_MAJOR_VERSION >= 3 static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, "_wrappers", /* m_name */ @@ -3095,18 +2837,13 @@ static struct PyModuleDef moduledef = { NULL, /* m_clear */ NULL, /* m_free */ }; -#endif -static PyObject * -moduleinit(void) +PyMODINIT_FUNC +PyInit__wrappers(void) { PyObject *module; -#if PY_MAJOR_VERSION >= 3 module = PyModule_Create(&moduledef); -#else - module = Py_InitModule3("_wrappers", NULL, NULL); -#endif if (module == NULL) return NULL; @@ -3155,16 +2892,4 @@ moduleinit(void) return module; } -#if PY_MAJOR_VERSION < 3 -PyMODINIT_FUNC init_wrappers(void) -{ - moduleinit(); -} -#else -PyMODINIT_FUNC PyInit__wrappers(void) -{ - return moduleinit(); -} -#endif - /* ------------------------------------------------------------------------- */ diff --git a/src/wrapt/decorators.py b/src/wrapt/decorators.py index 389a764b..4da34493 100644 --- a/src/wrapt/decorators.py +++ b/src/wrapt/decorators.py @@ -4,32 +4,6 @@ """ import sys - -PY2 = sys.version_info[0] == 2 - -if PY2: - string_types = basestring, - - def exec_(_code_, _globs_=None, _locs_=None): - """Execute code in a namespace.""" - if _globs_ is None: - frame = sys._getframe(1) - _globs_ = frame.f_globals - if _locs_ is None: - _locs_ = frame.f_locals - del frame - elif _locs_ is None: - _locs_ = _globs_ - exec("""exec _code_ in _globs_, _locs_""") - -else: - string_types = str, - - import builtins - - exec_ = getattr(builtins, "exec") - del builtins - from functools import partial from inspect import ismethod, isclass, formatargspec from collections import namedtuple @@ -101,10 +75,6 @@ def __signature__(self): else: return signature(self._self_adapter) - if PY2: - func_code = __code__ - func_defaults = __defaults__ - class _BoundAdapterWrapper(BoundFunctionWrapper): @property @@ -119,9 +89,6 @@ def __signature__(self): else: return signature(self._self_parent._self_adapter) - if PY2: - im_func = __func__ - class AdapterWrapper(FunctionWrapper): __bound_function_wrapper__ = _BoundAdapterWrapper @@ -145,10 +112,6 @@ def __defaults__(self): def __kwdefaults__(self): return self._self_surrogate.__kwdefaults__ - if PY2: - func_code = __code__ - func_defaults = __defaults__ - @property def __signature__(self): return self._self_surrogate.__signature__ @@ -219,13 +182,13 @@ def _build(wrapped, wrapper, enabled=None, adapter=None): annotations = {} - if not isinstance(adapter, string_types): + if not isinstance(adapter, str): if len(adapter) == 7: annotations = adapter[-1] adapter = adapter[:-1] adapter = formatargspec(*adapter) - exec_('def adapter{}: pass'.format(adapter), ns, ns) + exec('def adapter{}: pass'.format(adapter), ns, ns) adapter = ns['adapter'] # Override the annotations for the manufactured diff --git a/src/wrapt/importer.py b/src/wrapt/importer.py index 2c9db6fb..11031ee2 100644 --- a/src/wrapt/importer.py +++ b/src/wrapt/importer.py @@ -3,17 +3,10 @@ """ +import importlib import sys import threading -PY2 = sys.version_info[0] == 2 - -if PY2: - string_types = basestring, -else: - import importlib - string_types = str, - from .decorators import synchronized # The dictionary registering any post import hooks to be triggered once @@ -49,7 +42,7 @@ def register_post_import_hook(hook, name): # Create a deferred import hook if hook is a string name rather than # a callable function. - if isinstance(hook, string_types): + if isinstance(hook, str): hook = _create_import_hook_from_string(hook) # Automatically install the import hook finder if it has not already @@ -187,35 +180,20 @@ def find_module(self, fullname, path=None): # Now call back into the import system again. try: - if PY2: - # For Python 2 we don't have much choice but to - # call back in to __import__(). This will - # actually cause the module to be imported. If no - # module could be found then ImportError will be - # raised. Otherwise we return a loader which - # returns the already loaded module and invokes - # the post import hooks. - - __import__(fullname) - - return _ImportHookLoader() - - else: - # For Python 3 we need to use find_spec().loader - # from the importlib.util module. It doesn't actually - # import the target module and only finds the - # loader. If a loader is found, we need to return - # our own loader which will then in turn call the - # real loader to import the module and invoke the - # post import hooks. - try: - import importlib.util - loader = importlib.util.find_spec(fullname).loader - except (ImportError, AttributeError): - loader = importlib.find_loader(fullname, path) - if loader: - return _ImportHookChainedLoader(loader) - + # For Python 3 we need to use find_spec().loader + # from the importlib.util module. It doesn't actually + # import the target module and only finds the + # loader. If a loader is found, we need to return + # our own loader which will then in turn call the + # real loader to import the module and invoke the + # post import hooks. + try: + import importlib.util + loader = importlib.util.find_spec(fullname).loader + except (ImportError, AttributeError): + loader = importlib.find_loader(fullname, path) + if loader: + return _ImportHookChainedLoader(loader) finally: del self.in_progress[fullname] diff --git a/src/wrapt/wrappers.py b/src/wrapt/wrappers.py index 2bc6136f..b5b55181 100644 --- a/src/wrapt/wrappers.py +++ b/src/wrapt/wrappers.py @@ -5,13 +5,6 @@ import weakref import inspect -PY2 = sys.version_info[0] == 2 - -if PY2: - string_types = basestring, -else: - string_types = str, - def with_metaclass(meta, *bases): """Create a base class with a metaclass.""" return meta("NewBase", bases, {}) @@ -116,9 +109,8 @@ def __dir__(self): def __str__(self): return str(self.__wrapped__) - if not PY2: - def __bytes__(self): - return bytes(self.__wrapped__) + def __bytes__(self): + return bytes(self.__wrapped__) def __repr__(self): return '<{} at 0x{:x} for {} at 0x{:x}>'.format( @@ -129,9 +121,8 @@ def __repr__(self): def __reversed__(self): return reversed(self.__wrapped__) - if not PY2: - def __round__(self): - return round(self.__wrapped__) + def __round__(self): + return round(self.__wrapped__) if sys.hexversion >= 0x03070000: def __mro_entries__(self, bases): @@ -764,7 +755,7 @@ def __init__(self, wrapped, wrapper, enabled=None): # Helper functions for applying wrappers to existing functions. def resolve_path(module, name): - if isinstance(module, string_types): + if isinstance(module, str): __import__(module) module = sys.modules[module] diff --git a/tests/compat.py b/tests/compat.py deleted file mode 100644 index 0eed716e..00000000 --- a/tests/compat.py +++ /dev/null @@ -1,28 +0,0 @@ -import sys - -PY2 = sys.version_info[0] < 3 -PY3 = sys.version_info[0] >= 3 - -PYXY = tuple(sys.version_info[:2]) - -if PY3: - import builtins - exec_ = getattr(builtins, "exec") - del builtins - -else: - def exec_(_code_, _globs_=None, _locs_=None): - """Execute code in a namespace.""" - if _globs_ is None: - frame = sys._getframe(1) - _globs_ = frame.f_globals - if _locs_ is None: - _locs_ = frame.f_locals - del frame - elif _locs_ is None: - _locs_ = _globs_ - exec("""exec _code_ in _globs_, _locs_""") - - exec_("""def reraise(tp, value, tb=None): - raise tp, value, tb -""") diff --git a/tests/test_adapter.py b/tests/test_adapter.py index 14ba6604..e47ae088 100644 --- a/tests/test_adapter.py +++ b/tests/test_adapter.py @@ -1,13 +1,9 @@ -from __future__ import print_function - import unittest import inspect import imp import wrapt -from compat import PY2, PY3, exec_ - DECORATORS_CODE = """ import wrapt @@ -19,7 +15,7 @@ def adapter1(wrapped, instance, args, kwargs): """ decorators = imp.new_module('decorators') -exec_(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) +exec(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) def function1(arg1, arg2): '''documentation''' @@ -88,9 +84,6 @@ def test_signature(self): # actually needs to match that of the adapter function the # prototype of which was supplied via the dummy function. - if PY2: - return - def _adapter(arg1, arg2, arg3=None, *args, **kwargs): pass function1a_signature = str(inspect.signature(_adapter)) diff --git a/tests/test_adapter_py3.py b/tests/test_adapter_py3.py index 02c360f7..dfefe11b 100644 --- a/tests/test_adapter_py3.py +++ b/tests/test_adapter_py3.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import inspect import unittest import imp @@ -9,8 +7,6 @@ import wrapt -from compat import PY2, PY3, exec_ - DECORATORS_CODE = """ import wrapt from typing import Iterable @@ -29,7 +25,7 @@ def adapter2(wrapped, instance, args, kwargs): """ decorators = imp.new_module('decorators') -exec_(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) +exec(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) def function1(arg1, arg2) -> Iterable: '''documentation''' @@ -89,9 +85,6 @@ def test_signature(self): # actually needs to match that of the adapter function the # prototype of which was supplied via the dummy function. - if PY2: - return - def _adapter(arg1, arg2, arg3=None, *args, **kwargs) -> Iterable: pass function1a_signature = str(inspect.signature(_adapter)) diff --git a/tests/test_adapter_py33.py b/tests/test_adapter_py33.py index 063fba06..3d654433 100644 --- a/tests/test_adapter_py33.py +++ b/tests/test_adapter_py33.py @@ -1,13 +1,9 @@ -from __future__ import print_function - import unittest import inspect import imp import wrapt -from compat import PY2, PY3, exec_ - DECORATORS_CODE = """ import wrapt @@ -19,7 +15,7 @@ def adapter1(wrapped, instance, args, kwargs): """ decorators = imp.new_module('decorators') -exec_(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) +exec(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) def function1(arg1, arg2): '''documentation''' @@ -52,9 +48,6 @@ def test_signature(self): # actually needs to match that of the adapter function the # prototype of which was supplied via the dummy function. - if PY2: - return - def _adapter(arg1, arg2, *, arg3=None, **kwargs): pass function1a_signature = str(inspect.signature(_adapter)) diff --git a/tests/test_arguments.py b/tests/test_arguments.py index 0b7379d3..274d9393 100644 --- a/tests/test_arguments.py +++ b/tests/test_arguments.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import unittest import wrapt diff --git a/tests/test_attribute_wrapper.py b/tests/test_attribute_wrapper.py index f68315aa..6fcd5f25 100644 --- a/tests/test_attribute_wrapper.py +++ b/tests/test_attribute_wrapper.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import unittest import wrapt diff --git a/tests/test_callable_object_proxy.py b/tests/test_callable_object_proxy.py index 5421a06a..e9b5a7f9 100644 --- a/tests/test_callable_object_proxy.py +++ b/tests/test_callable_object_proxy.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import unittest import wrapt diff --git a/tests/test_class.py b/tests/test_class.py index cf3b7e57..e1e8bffc 100644 --- a/tests/test_class.py +++ b/tests/test_class.py @@ -1,13 +1,9 @@ -from __future__ import print_function - import unittest import inspect import imp import wrapt -from compat import PY2, PY3, exec_ - DECORATORS_CODE = """ import wrapt @@ -17,7 +13,7 @@ def passthru_decorator(wrapped, instance, args, kwargs): """ decorators = imp.new_module('decorators') -exec_(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) +exec(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) class class1(object): pass diff --git a/tests/test_class_py37.py b/tests/test_class_py37.py index 435b46e2..a71712d2 100644 --- a/tests/test_class_py37.py +++ b/tests/test_class_py37.py @@ -1,13 +1,9 @@ -from __future__ import print_function - import unittest import inspect import imp import wrapt -from compat import PY2, PY3, exec_ - class TestInheritance(unittest.TestCase): def test_single_inheritance(self): diff --git a/tests/test_copy.py b/tests/test_copy.py index cbce9280..41bcfcf1 100644 --- a/tests/test_copy.py +++ b/tests/test_copy.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import unittest import copy diff --git a/tests/test_decorators.py b/tests/test_decorators.py index 2213abc9..844f6308 100644 --- a/tests/test_decorators.py +++ b/tests/test_decorators.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import unittest import wrapt diff --git a/tests/test_descriptors_py36.py b/tests/test_descriptors_py36.py index 2b51a740..4896efd3 100644 --- a/tests/test_descriptors_py36.py +++ b/tests/test_descriptors_py36.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import unittest import wrapt diff --git a/tests/test_function.py b/tests/test_function.py index 64a71083..129bd08f 100644 --- a/tests/test_function.py +++ b/tests/test_function.py @@ -1,13 +1,9 @@ -from __future__ import print_function - import unittest import inspect import imp import wrapt -from compat import PY2, PY3, exec_ - DECORATORS_CODE = """ import wrapt @@ -17,7 +13,7 @@ def passthru_decorator(wrapped, instance, args, kwargs): """ decorators = imp.new_module('decorators') -exec_(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) +exec(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) def function1(arg): '''documentation''' diff --git a/tests/test_function_wrapper.py b/tests/test_function_wrapper.py index 3e95ba3b..b655eb8a 100644 --- a/tests/test_function_wrapper.py +++ b/tests/test_function_wrapper.py @@ -1,12 +1,8 @@ -from __future__ import print_function - import unittest import wrapt import wrapt.wrappers -from compat import PY2, PY3, exec_ - class TestClassInheritence(unittest.TestCase): def test_function_type_inheritence(self): diff --git a/tests/test_inheritance_py37.py b/tests/test_inheritance_py37.py index b11e08bf..5cff79bc 100644 --- a/tests/test_inheritance_py37.py +++ b/tests/test_inheritance_py37.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import unittest import abc diff --git a/tests/test_inner_classmethod.py b/tests/test_inner_classmethod.py index abf4ca16..084202ff 100644 --- a/tests/test_inner_classmethod.py +++ b/tests/test_inner_classmethod.py @@ -1,13 +1,9 @@ -from __future__ import print_function - import unittest import inspect import imp import wrapt -from compat import PY2, PY3, exec_ - DECORATORS_CODE = """ import wrapt @@ -17,7 +13,7 @@ def passthru_decorator(wrapped, instance, args, kwargs): """ decorators = imp.new_module('decorators') -exec_(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) +exec(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) class Class(object): @classmethod diff --git a/tests/test_inner_staticmethod.py b/tests/test_inner_staticmethod.py index 01a54bae..cfa7dcba 100644 --- a/tests/test_inner_staticmethod.py +++ b/tests/test_inner_staticmethod.py @@ -1,13 +1,9 @@ -from __future__ import print_function - import unittest import inspect import imp import wrapt -from compat import PY2, PY3, exec_ - DECORATORS_CODE = """ import wrapt @@ -17,7 +13,7 @@ def passthru_decorator(wrapped, instance, args, kwargs): """ decorators = imp.new_module('decorators') -exec_(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) +exec(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) class Class(object): @staticmethod diff --git a/tests/test_instancemethod.py b/tests/test_instancemethod.py index b6356bd0..c1b9d6ae 100644 --- a/tests/test_instancemethod.py +++ b/tests/test_instancemethod.py @@ -1,13 +1,9 @@ -from __future__ import print_function - import unittest import inspect import imp import wrapt -from compat import PY2, PY3, exec_ - DECORATORS_CODE = """ import wrapt @@ -17,7 +13,7 @@ def passthru_decorator(wrapped, instance, args, kwargs): """ decorators = imp.new_module('decorators') -exec_(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) +exec(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) class OldClass1(): def function(self, arg): diff --git a/tests/test_memoize.py b/tests/test_memoize.py index 27d3f5d2..8cd93d7f 100644 --- a/tests/test_memoize.py +++ b/tests/test_memoize.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import unittest import threading import inspect diff --git a/tests/test_monkey_patching.py b/tests/test_monkey_patching.py index 5e290f5d..a543677f 100644 --- a/tests/test_monkey_patching.py +++ b/tests/test_monkey_patching.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import unittest import sys diff --git a/tests/test_nested_function.py b/tests/test_nested_function.py index 4f55a36b..2f1976ab 100644 --- a/tests/test_nested_function.py +++ b/tests/test_nested_function.py @@ -1,13 +1,9 @@ -from __future__ import print_function - import unittest import inspect import imp import wrapt -from compat import PY2, PY3, exec_ - DECORATORS_CODE = """ import wrapt @@ -17,7 +13,7 @@ def passthru_decorator(wrapped, instance, args, kwargs): """ decorators = imp.new_module('decorators') -exec_(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) +exec(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) def function1(): def inner(arg): diff --git a/tests/test_object_proxy.py b/tests/test_object_proxy.py index e2493063..ae28b646 100644 --- a/tests/test_object_proxy.py +++ b/tests/test_object_proxy.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import unittest import imp import operator @@ -9,8 +7,6 @@ import wrapt -from compat import PY2, PY3, exec_ - OBJECTS_CODE = """ class TargetBaseClass(object): "documentation" @@ -24,7 +20,7 @@ def target(): """ objects = imp.new_module('objects') -exec_(OBJECTS_CODE, objects.__dict__, objects.__dict__) +exec(OBJECTS_CODE, objects.__dict__, objects.__dict__) class TestAttributeAccess(unittest.TestCase): @@ -68,9 +64,7 @@ def function1(*args, **kwargs): self.assertEqual(function2, function1) self.assertEqual(function2.__wrapped__, function1) self.assertEqual(function2.__name__, function1.__name__) - - if PY3: - self.assertEqual(function2.__qualname__, function1.__qualname__) + self.assertEqual(function2.__qualname__, function1.__qualname__) function2.__wrapped__ = None @@ -79,9 +73,7 @@ def function1(*args, **kwargs): self.assertEqual(function2, None) self.assertEqual(function2.__wrapped__, None) self.assertFalse(hasattr(function2, '__name__')) - - if PY3: - self.assertFalse(hasattr(function2, '__qualname__')) + self.assertFalse(hasattr(function2, '__qualname__')) def function3(*args, **kwargs): return args, kwargs @@ -91,9 +83,7 @@ def function3(*args, **kwargs): self.assertEqual(function2, function3) self.assertEqual(function2.__wrapped__, function3) self.assertEqual(function2.__name__, function3.__name__) - - if PY3: - self.assertEqual(function2.__qualname__, function3.__qualname__) + self.assertEqual(function2.__qualname__, function3.__qualname__) def test_delete_wrapped(self): def function1(*args, **kwargs): @@ -824,9 +814,6 @@ def test_int(self): self.assertEqual(int(one), 1) - if not PY3: - self.assertEqual(long(one), 1) - def test_float(self): one = wrapt.ObjectProxy(1) @@ -1742,15 +1729,14 @@ def test_callable_proxy_is_callable(self): class SpecialMethods(unittest.TestCase): def test_class_bytes(self): - if PY3: - class Class(object): - def __bytes__(self): - return b'BYTES' - instance = Class() + class Class(object): + def __bytes__(self): + return b'BYTES' + instance = Class() - proxy = wrapt.ObjectProxy(instance) + proxy = wrapt.ObjectProxy(instance) - self.assertEqual(bytes(instance), bytes(proxy)) + self.assertEqual(bytes(instance), bytes(proxy)) def test_str_format(self): instance = 'abcd' diff --git a/tests/test_outer_classmethod.py b/tests/test_outer_classmethod.py index fbf37f7a..777dc11d 100644 --- a/tests/test_outer_classmethod.py +++ b/tests/test_outer_classmethod.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import sys import unittest import inspect @@ -7,7 +5,6 @@ import wrapt -from compat import PY2, PY3, PYXY, exec_ DECORATORS_CODE = """ import wrapt @@ -18,7 +15,7 @@ def passthru_decorator(wrapped, instance, args, kwargs): """ decorators = imp.new_module('decorators') -exec_(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) +exec(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) class Class(object): @classmethod @@ -136,7 +133,7 @@ def test_class_call_function(self): @wrapt.decorator def _decorator(wrapped, instance, args, kwargs): - if PYXY < (3, 9): + if sys.version_info < (3, 9): self.assertEqual(instance, None) self.assertEqual(args, (Class,)+_args) else: @@ -178,7 +175,7 @@ def test_instance_call_function(self): @wrapt.decorator def _decorator(wrapped, instance, args, kwargs): - if PYXY < (3, 9): + if sys.version_info < (3, 9): self.assertEqual(instance, None) self.assertEqual(args, (Class,)+_args) else: diff --git a/tests/test_outer_staticmethod.py b/tests/test_outer_staticmethod.py index 0a0d0f77..836ae673 100644 --- a/tests/test_outer_staticmethod.py +++ b/tests/test_outer_staticmethod.py @@ -1,13 +1,9 @@ -from __future__ import print_function - import unittest import inspect import imp import wrapt -from compat import PY2, PY3, exec_ - DECORATORS_CODE = """ import wrapt @@ -17,7 +13,7 @@ def passthru_decorator(wrapped, instance, args, kwargs): """ decorators = imp.new_module('decorators') -exec_(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) +exec(DECORATORS_CODE, decorators.__dict__, decorators.__dict__) class Class(object): @staticmethod diff --git a/tests/test_pickle.py b/tests/test_pickle.py index 41e91044..f3e085d2 100644 --- a/tests/test_pickle.py +++ b/tests/test_pickle.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import unittest import pickle diff --git a/tests/test_post_import_hooks.py b/tests/test_post_import_hooks.py index b7d65882..77f583c8 100644 --- a/tests/test_post_import_hooks.py +++ b/tests/test_post_import_hooks.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import unittest import sys diff --git a/tests/test_synchronized_lock.py b/tests/test_synchronized_lock.py index 0e43f7af..f20eb1e3 100644 --- a/tests/test_synchronized_lock.py +++ b/tests/test_synchronized_lock.py @@ -1,11 +1,8 @@ -from __future__ import print_function - +import sys import unittest import wrapt -from compat import PYXY - @wrapt.synchronized def function(): print('function') @@ -166,7 +163,7 @@ def test_synchronized_outer_classmethod(self): # explicitly passing the class as first argument. For more # details see: https://bugs.python.org/issue19072 - if PYXY < (3, 9): + if sys.version_info < (3, 9): _lock0 = getattr(C4.function2, '_synchronized_lock', None) else: _lock0 = getattr(C4, '_synchronized_lock', None) @@ -174,7 +171,7 @@ def test_synchronized_outer_classmethod(self): c4.function2() - if PYXY < (3, 9): + if sys.version_info < (3, 9): _lock1 = getattr(C4.function2, '_synchronized_lock', None) else: _lock1 = getattr(C4, '_synchronized_lock', None) @@ -182,7 +179,7 @@ def test_synchronized_outer_classmethod(self): C4.function2() - if PYXY < (3, 9): + if sys.version_info < (3, 9): _lock2 = getattr(C4.function2, '_synchronized_lock', None) else: _lock2 = getattr(C4, '_synchronized_lock', None) @@ -191,7 +188,7 @@ def test_synchronized_outer_classmethod(self): C4.function2() - if PYXY < (3, 9): + if sys.version_info < (3, 9): _lock3 = getattr(C4.function2, '_synchronized_lock', None) else: _lock3 = getattr(C4, '_synchronized_lock', None) diff --git a/tests/test_update_attributes.py b/tests/test_update_attributes.py index 9850c1b1..b2e3f0ae 100644 --- a/tests/test_update_attributes.py +++ b/tests/test_update_attributes.py @@ -1,11 +1,7 @@ -from __future__ import print_function - import unittest import wrapt -from compat import PY2, PY3, exec_ - @wrapt.decorator def passthru_decorator(wrapped, instance, args, kwargs): return wrapped(*args, **kwargs) @@ -45,10 +41,9 @@ def test_update_qualname(self): def function(): pass - if PY3: - method = self.test_update_qualname - self.assertEqual(function.__qualname__, - (method.__qualname__ + '..function')) + method = self.test_update_qualname + self.assertEqual(function.__qualname__, + (method.__qualname__ + '..function')) function.__qualname__ = 'override_qualname' @@ -63,10 +58,9 @@ def wrapper(wrapped, instance, args, kwargs): instance = wrapt.FunctionWrapper(function, wrapper) - if PY3: - method = self.test_update_qualname_modified_on_original - self.assertEqual(instance.__qualname__, - (method.__qualname__ + '..function')) + method = self.test_update_qualname_modified_on_original + self.assertEqual(instance.__qualname__, + (method.__qualname__ + '..function')) instance.__qualname__ = 'override_qualname' @@ -134,14 +128,7 @@ def test_update_annotations(self): def function(): pass - if PY3: - self.assertEqual(function.__annotations__, {}) - - else: - def run(*args): - function.__annotations__ - - self.assertRaises(AttributeError, run, ()) + self.assertEqual(function.__annotations__, {}) override_annotations = {'override_annotations': ''} function.__annotations__ = override_annotations @@ -158,14 +145,7 @@ def wrapper(wrapped, instance, args, kwargs): instance = wrapt.FunctionWrapper(function, wrapper) - if PY3: - self.assertEqual(instance.__annotations__, {}) - - else: - def run(*args): - instance.__annotations__ - - self.assertRaises(AttributeError, run, ()) + self.assertEqual(instance.__annotations__, {}) override_annotations = {'override_annotations': ''} instance.__annotations__ = override_annotations diff --git a/tests/test_weak_function_proxy.py b/tests/test_weak_function_proxy.py index d34da0e1..0a87314a 100644 --- a/tests/test_weak_function_proxy.py +++ b/tests/test_weak_function_proxy.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import unittest import gc