Skip to content

Commit 446bce5

Browse files
committed
Move to dataclass for vc args
1 parent e9aff2f commit 446bce5

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

Tools/clinic/libclinic/dsl_parser.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
fail, warn, unspecified, unknown, NULL)
1717
from libclinic.function import (
1818
Module, Class, Function, Parameter,
19-
FunctionKind,
19+
FunctionKind, VectorcallOptions,
2020
CALLABLE, STATIC_METHOD, CLASS_METHOD, METHOD_INIT, METHOD_NEW,
2121
GETTER, SETTER)
2222
from libclinic.converter import (
@@ -302,8 +302,7 @@ def reset(self) -> None:
302302
self.critical_section = False
303303
self.target_critical_section = []
304304
self.disable_fastcall = False
305-
self.vectorcall = False
306-
self.vectorcall_exact_only = False
305+
self.vectorcall: VectorcallOptions | None = None
307306
self.permit_long_summary = False
308307
self.permit_long_docstring_body = False
309308

@@ -469,18 +468,19 @@ def at_staticmethod(self) -> None:
469468
self.kind = STATIC_METHOD
470469

471470
def at_vectorcall(self, *args: str) -> None:
472-
if self.vectorcall:
471+
if self.vectorcall is not None:
473472
fail("Called @vectorcall twice!")
474-
self.vectorcall = True
473+
exact_only = False
475474
for arg in args:
476475
if '=' in arg:
477476
key = arg.split('=', 1)[0]
478477
else:
479478
key = arg
480479
if key == 'exact_only':
481-
self.vectorcall_exact_only = True
480+
exact_only = True
482481
else:
483482
fail(f"@vectorcall: unknown argument {key!r}")
483+
self.vectorcall = VectorcallOptions(exact_only=exact_only)
484484

485485
def at_coexist(self) -> None:
486486
if self.coexist:
@@ -745,7 +745,6 @@ def state_modulename_name(self, line: str) -> None:
745745
target_critical_section=self.target_critical_section,
746746
forced_text_signature=self.forced_text_signature,
747747
vectorcall=self.vectorcall,
748-
vectorcall_exact_only=self.vectorcall_exact_only,
749748
)
750749
self.add_function(func)
751750

Tools/clinic/libclinic/function.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ def __repr__(self) -> str:
7878
SETTER: Final = FunctionKind.SETTER
7979

8080

81+
@dc.dataclass
82+
class VectorcallOptions:
83+
exact_only: bool = False
84+
85+
8186
@dc.dataclass(repr=False)
8287
class Function:
8388
"""
@@ -111,8 +116,7 @@ class Function:
111116
critical_section: bool = False
112117
disable_fastcall: bool = False
113118
target_critical_section: list[str] = dc.field(default_factory=list)
114-
vectorcall: bool = False
115-
vectorcall_exact_only: bool = False
119+
vectorcall: VectorcallOptions | None = None
116120

117121
def __post_init__(self) -> None:
118122
self.parent = self.cls or self.module

Tools/clinic/libclinic/parse_args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ def generate_vectorcall(self) -> str:
12291229

12301230
# Exact type check (if vectorcall_exact_only)
12311231
exact_check = ""
1232-
if func.vectorcall_exact_only and func.cls:
1232+
if func.vectorcall and func.vectorcall.exact_only and func.cls:
12331233
type_obj = func.cls.type_object
12341234
self.codegen.add_include('pycore_call.h',
12351235
'_PyObject_MakeTpCall()')

0 commit comments

Comments
 (0)