The oldest CAPI version we support right now is 3.7 (#15839)
Looks like `capi_version < 3.7` is not supported, so I changed the
lowest version to be `3.7`.
Based on the discord discussion.
diff --git a/mypyc/codegen/emitclass.py b/mypyc/codegen/emitclass.py
index 84d19d6..62e1b4b 100644
--- a/mypyc/codegen/emitclass.py
+++ b/mypyc/codegen/emitclass.py
@@ -18,7 +18,7 @@
generate_richcompare_wrapper,
generate_set_del_item_wrapper,
)
-from mypyc.common import BITMAP_BITS, BITMAP_TYPE, NATIVE_PREFIX, PREFIX, REG_PREFIX, use_fastcall
+from mypyc.common import BITMAP_BITS, BITMAP_TYPE, NATIVE_PREFIX, PREFIX, REG_PREFIX
from mypyc.ir.class_ir import ClassIR, VTableEntries
from mypyc.ir.func_ir import FUNC_CLASSMETHOD, FUNC_STATICMETHOD, FuncDecl, FuncIR
from mypyc.ir.rtypes import RTuple, RType, object_rprimitive
@@ -794,11 +794,7 @@
continue
emitter.emit_line(f'{{"{fn.name}",')
emitter.emit_line(f" (PyCFunction){PREFIX}{fn.cname(emitter.names)},")
- if use_fastcall(emitter.capi_version):
- flags = ["METH_FASTCALL"]
- else:
- flags = ["METH_VARARGS"]
- flags.append("METH_KEYWORDS")
+ flags = ["METH_FASTCALL", "METH_KEYWORDS"]
if fn.decl.kind == FUNC_STATICMETHOD:
flags.append("METH_STATIC")
elif fn.decl.kind == FUNC_CLASSMETHOD:
diff --git a/mypyc/codegen/emitmodule.py b/mypyc/codegen/emitmodule.py
index f360fab..caf2058 100644
--- a/mypyc/codegen/emitmodule.py
+++ b/mypyc/codegen/emitmodule.py
@@ -43,7 +43,6 @@
TOP_LEVEL_NAME,
shared_lib_name,
short_id_from_name,
- use_fastcall,
use_vectorcall,
)
from mypyc.errors import Errors
@@ -1107,8 +1106,8 @@
# We can use vectorcalls (PEP 590) when supported
return use_vectorcall(capi_version)
# TODO: Support fastcall for __init__.
- return use_fastcall(capi_version) and fn.name != "__init__"
- return use_fastcall(capi_version)
+ return fn.name != "__init__"
+ return True
def collect_literals(fn: FuncIR, literals: Literals) -> None:
diff --git a/mypyc/common.py b/mypyc/common.py
index 4615bf3..3d07f6c 100644
--- a/mypyc/common.py
+++ b/mypyc/common.py
@@ -98,11 +98,6 @@
return name
-def use_fastcall(capi_version: tuple[int, int]) -> bool:
- # We can use METH_FASTCALL for faster wrapper functions on Python 3.7+.
- return capi_version >= (3, 7)
-
-
def use_vectorcall(capi_version: tuple[int, int]) -> bool:
# We can use vectorcalls to make calls on Python 3.8+ (PEP 590).
return capi_version >= (3, 8)
diff --git a/mypyc/test/testutil.py b/mypyc/test/testutil.py
index 796811a..6446af3 100644
--- a/mypyc/test/testutil.py
+++ b/mypyc/test/testutil.py
@@ -102,7 +102,7 @@
# By default generate IR compatible with the earliest supported Python C API.
# If a test needs more recent API features, this should be overridden.
- compiler_options = compiler_options or CompilerOptions(capi_version=(3, 5))
+ compiler_options = compiler_options or CompilerOptions(capi_version=(3, 7))
options = Options()
options.show_traceback = True
options.hide_error_codes = True
@@ -272,7 +272,7 @@
return None
if "_32bit" in name and not IS_32_BIT_PLATFORM:
return None
- options = CompilerOptions(strip_asserts="StripAssert" in name, capi_version=(3, 5))
+ options = CompilerOptions(strip_asserts="StripAssert" in name, capi_version=(3, 7))
# A suffix like _python3.8 is used to set the target C API version.
m = re.search(r"_python([3-9]+)_([0-9]+)(_|\b)", name)
if m: