From 4259e37875219d30427a66304033f661f8b47f8f Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sat, 9 Mar 2024 16:31:16 +0200 Subject: [PATCH] Remove redundant Python 3.7 code (#17004) Some follow on from https://github.com/python/mypy/pull/15566. Also add 3.12 to tox.ini. --- mypy/modulefinder.py | 4 ++-- mypy/stubgenc.py | 2 +- mypy/util.py | 2 +- mypyc/lib-rt/CPy.h | 5 ----- mypyc/lib-rt/pythonsupport.h | 15 --------------- tox.ini | 1 + 6 files changed, 5 insertions(+), 24 deletions(-) diff --git a/mypy/modulefinder.py b/mypy/modulefinder.py index 455aa40e5975..452cfef20f4c 100644 --- a/mypy/modulefinder.py +++ b/mypy/modulefinder.py @@ -870,6 +870,6 @@ def parse_version(version: str) -> tuple[int, int]: def typeshed_py_version(options: Options) -> tuple[int, int]: """Return Python version used for checking whether module supports typeshed.""" - # Typeshed no longer covers Python 3.x versions before 3.7, so 3.7 is + # Typeshed no longer covers Python 3.x versions before 3.8, so 3.8 is # the earliest we can support. - return max(options.python_version, (3, 7)) + return max(options.python_version, (3, 8)) diff --git a/mypy/stubgenc.py b/mypy/stubgenc.py index 3bec0c246d9a..29b2636d39cc 100755 --- a/mypy/stubgenc.py +++ b/mypy/stubgenc.py @@ -495,7 +495,7 @@ def get_type_annotation(self, obj: object) -> str: if obj is None or obj is type(None): return "None" elif inspect.isclass(obj): - return "type[{}]".format(self.get_type_fullname(obj)) + return f"type[{self.get_type_fullname(obj)}]" elif isinstance(obj, FunctionType): return self.add_name("typing.Callable") elif isinstance(obj, ModuleType): diff --git a/mypy/util.py b/mypy/util.py index 968774ee7c98..bbb5a8610f7f 100644 --- a/mypy/util.py +++ b/mypy/util.py @@ -298,7 +298,7 @@ def _generate_junit_contents( text=escape("\n".join(messages)), filename="mypy", time=dt, - name="mypy-py{ver}-{platform}".format(ver=version, platform=platform), + name=f"mypy-py{version}-{platform}", ) xml += JUNIT_FOOTER diff --git a/mypyc/lib-rt/CPy.h b/mypyc/lib-rt/CPy.h index 64b716945b94..1a03f049ecb0 100644 --- a/mypyc/lib-rt/CPy.h +++ b/mypyc/lib-rt/CPy.h @@ -544,13 +544,8 @@ void CPy_AttributeError(const char *filename, const char *funcname, const char * // Misc operations -#if PY_VERSION_HEX >= 0x03080000 #define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_BEGIN(op, dealloc) #define CPy_TRASHCAN_END(op) Py_TRASHCAN_END -#else -#define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_SAFE_BEGIN(op) -#define CPy_TRASHCAN_END(op) Py_TRASHCAN_SAFE_END(op) -#endif // Tweaked version of _PyArg_Parser in CPython typedef struct CPyArg_Parser { diff --git a/mypyc/lib-rt/pythonsupport.h b/mypyc/lib-rt/pythonsupport.h index 1d493b45b89d..f7d501f44a27 100644 --- a/mypyc/lib-rt/pythonsupport.h +++ b/mypyc/lib-rt/pythonsupport.h @@ -354,21 +354,6 @@ list_count(PyListObject *self, PyObject *value) return CPyTagged_ShortFromSsize_t(count); } -#if PY_VERSION_HEX < 0x03080000 -static PyObject * -_PyDict_GetItemStringWithError(PyObject *v, const char *key) -{ - PyObject *kv, *rv; - kv = PyUnicode_FromString(key); - if (kv == NULL) { - return NULL; - } - rv = PyDict_GetItemWithError(v, kv); - Py_DECREF(kv); - return rv; -} -#endif - #define CPyUnicode_EqualToASCIIString(x, y) _PyUnicode_EqualToASCIIString(x, y) // Adapted from genobject.c in Python 3.7.2 diff --git a/tox.ini b/tox.ini index 31aed1a1ef48..c2abd05d7b6c 100644 --- a/tox.ini +++ b/tox.ini @@ -6,6 +6,7 @@ envlist = py39, py310, py311, + py312, docs, lint, type,