Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 67b9c81

Browse files
authored
[librt.internal] Make various functions take positional-only args (#20623)
The wrapper functions will be slighly faster, so this may improve interpreted mypy performance.
1 parent 6439b29 commit 67b9c81

2 files changed

Lines changed: 90 additions & 90 deletions

File tree

mypy/typeshed/stubs/librt/librt/internal.pyi

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ class ReadBuffer:
66
class WriteBuffer:
77
def getvalue(self) -> bytes: ...
88

9-
def write_bool(data: WriteBuffer, value: bool) -> None: ...
10-
def read_bool(data: ReadBuffer) -> bool: ...
11-
def write_str(data: WriteBuffer, value: str) -> None: ...
12-
def read_str(data: ReadBuffer) -> str: ...
13-
def write_bytes(data: WriteBuffer, value: bytes) -> None: ...
14-
def read_bytes(data: ReadBuffer) -> bytes: ...
15-
def write_float(data: WriteBuffer, value: float) -> None: ...
16-
def read_float(data: ReadBuffer) -> float: ...
17-
def write_int(data: WriteBuffer, value: int) -> None: ...
18-
def read_int(data: ReadBuffer) -> int: ...
19-
def write_tag(data: WriteBuffer, value: u8) -> None: ...
20-
def read_tag(data: ReadBuffer) -> u8: ...
9+
def write_bool(data: WriteBuffer, value: bool, /) -> None: ...
10+
def read_bool(data: ReadBuffer, /) -> bool: ...
11+
def write_str(data: WriteBuffer, value: str, /) -> None: ...
12+
def read_str(data: ReadBuffer, /) -> str: ...
13+
def write_bytes(data: WriteBuffer, value: bytes, /) -> None: ...
14+
def read_bytes(data: ReadBuffer, /) -> bytes: ...
15+
def write_float(data: WriteBuffer, value: float, /) -> None: ...
16+
def read_float(data: ReadBuffer, /) -> float: ...
17+
def write_int(data: WriteBuffer, value: int, /) -> None: ...
18+
def read_int(data: ReadBuffer, /) -> int: ...
19+
def write_tag(data: WriteBuffer, value: u8, /) -> None: ...
20+
def read_tag(data: ReadBuffer, /) -> u8: ...
2121
def cache_version() -> u8: ...

mypyc/lib-rt/librt_internal.c

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,13 @@ read_bool_internal(PyObject *data) {
341341
}
342342

343343
static PyObject*
344-
read_bool(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames) {
345-
static const char * const kwlist[] = {"data", 0};
346-
static CPyArg_Parser parser = {"O:read_bool", kwlist, 0};
347-
PyObject *data;
348-
if (unlikely(!CPyArg_ParseStackAndKeywordsOneArg(args, nargs, kwnames, &parser, &data))) {
344+
read_bool(PyObject *self, PyObject *const *args, size_t nargs) {
345+
if (unlikely(nargs != 1)) {
346+
PyErr_Format(PyExc_TypeError,
347+
"read_bool() takes exactly 1 argument (%zu given)", nargs);
349348
return NULL;
350349
}
350+
PyObject *data = args[0];
351351
_CHECK_READ_BUFFER(data, NULL)
352352
char res = read_bool_internal(data);
353353
if (unlikely(res == CPY_BOOL_ERROR))
@@ -365,14 +365,14 @@ write_bool_internal(PyObject *data, char value) {
365365
}
366366

367367
static PyObject*
368-
write_bool(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames) {
369-
static const char * const kwlist[] = {"data", "value", 0};
370-
static CPyArg_Parser parser = {"OO:write_bool", kwlist, 0};
371-
PyObject *data;
372-
PyObject *value;
373-
if (unlikely(!CPyArg_ParseStackAndKeywordsSimple(args, nargs, kwnames, &parser, &data, &value))) {
368+
write_bool(PyObject *self, PyObject *const *args, size_t nargs) {
369+
if (unlikely(nargs != 2)) {
370+
PyErr_Format(PyExc_TypeError,
371+
"write_bool() takes exactly 2 arguments (%zu given)", nargs);
374372
return NULL;
375373
}
374+
PyObject *data = args[0];
375+
PyObject *value = args[1];
376376
_CHECK_WRITE_BUFFER(data, NULL)
377377
if (unlikely(!PyBool_Check(value))) {
378378
PyErr_SetString(PyExc_TypeError, "value must be a bool");
@@ -445,13 +445,13 @@ read_str_internal(PyObject *data) {
445445
}
446446

447447
static PyObject*
448-
read_str(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames) {
449-
static const char * const kwlist[] = {"data", 0};
450-
static CPyArg_Parser parser = {"O:read_str", kwlist, 0};
451-
PyObject *data;
452-
if (unlikely(!CPyArg_ParseStackAndKeywordsOneArg(args, nargs, kwnames, &parser, &data))) {
448+
read_str(PyObject *self, PyObject *const *args, size_t nargs) {
449+
if (unlikely(nargs != 1)) {
450+
PyErr_Format(PyExc_TypeError,
451+
"read_str() takes exactly 1 argument (%zu given)", nargs);
453452
return NULL;
454453
}
454+
PyObject *data = args[0];
455455
_CHECK_READ_BUFFER(data, NULL)
456456
return read_str_internal(data);
457457
}
@@ -506,14 +506,14 @@ write_str_internal(PyObject *data, PyObject *value) {
506506
}
507507

508508
static PyObject*
509-
write_str(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames) {
510-
static const char * const kwlist[] = {"data", "value", 0};
511-
static CPyArg_Parser parser = {"OO:write_str", kwlist, 0};
512-
PyObject *data;
513-
PyObject *value;
514-
if (unlikely(!CPyArg_ParseStackAndKeywordsSimple(args, nargs, kwnames, &parser, &data, &value))) {
509+
write_str(PyObject *self, PyObject *const *args, size_t nargs) {
510+
if (unlikely(nargs != 2)) {
511+
PyErr_Format(PyExc_TypeError,
512+
"write_str() takes exactly 2 arguments (%zu given)", nargs);
515513
return NULL;
516514
}
515+
PyObject *data = args[0];
516+
PyObject *value = args[1];
517517
_CHECK_WRITE_BUFFER(data, NULL)
518518
if (unlikely(!PyUnicode_Check(value))) {
519519
PyErr_SetString(PyExc_TypeError, "value must be a str");
@@ -561,13 +561,13 @@ read_bytes_internal(PyObject *data) {
561561
}
562562

563563
static PyObject*
564-
read_bytes(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames) {
565-
static const char * const kwlist[] = {"data", 0};
566-
static CPyArg_Parser parser = {"O:read_bytes", kwlist, 0};
567-
PyObject *data;
568-
if (unlikely(!CPyArg_ParseStackAndKeywordsOneArg(args, nargs, kwnames, &parser, &data))) {
564+
read_bytes(PyObject *self, PyObject *const *args, size_t nargs) {
565+
if (unlikely(nargs != 1)) {
566+
PyErr_Format(PyExc_TypeError,
567+
"read_bytes() takes exactly 1 argument (%zu given)", nargs);
569568
return NULL;
570569
}
570+
PyObject *data = args[0];
571571
_CHECK_READ_BUFFER(data, NULL)
572572
return read_bytes_internal(data);
573573
}
@@ -596,14 +596,14 @@ write_bytes_internal(PyObject *data, PyObject *value) {
596596
}
597597

598598
static PyObject*
599-
write_bytes(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames) {
600-
static const char * const kwlist[] = {"data", "value", 0};
601-
static CPyArg_Parser parser = {"OO:write_bytes", kwlist, 0};
602-
PyObject *data;
603-
PyObject *value;
604-
if (unlikely(!CPyArg_ParseStackAndKeywordsSimple(args, nargs, kwnames, &parser, &data, &value))) {
599+
write_bytes(PyObject *self, PyObject *const *args, size_t nargs) {
600+
if (unlikely(nargs != 2)) {
601+
PyErr_Format(PyExc_TypeError,
602+
"write_bytes() takes exactly 2 arguments (%zu given)", nargs);
605603
return NULL;
606604
}
605+
PyObject *data = args[0];
606+
PyObject *value = args[1];
607607
_CHECK_WRITE_BUFFER(data, NULL)
608608
if (unlikely(!PyBytes_Check(value))) {
609609
PyErr_SetString(PyExc_TypeError, "value must be a bytes object");
@@ -633,13 +633,13 @@ read_float_internal(PyObject *data) {
633633
}
634634

635635
static PyObject*
636-
read_float(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames) {
637-
static const char * const kwlist[] = {"data", 0};
638-
static CPyArg_Parser parser = {"O:read_float", kwlist, 0};
639-
PyObject *data;
640-
if (unlikely(!CPyArg_ParseStackAndKeywordsOneArg(args, nargs, kwnames, &parser, &data))) {
636+
read_float(PyObject *self, PyObject *const *args, size_t nargs) {
637+
if (unlikely(nargs != 1)) {
638+
PyErr_Format(PyExc_TypeError,
639+
"read_float() takes exactly 1 argument (%zu given)", nargs);
641640
return NULL;
642641
}
642+
PyObject *data = args[0];
643643
_CHECK_READ_BUFFER(data, NULL)
644644
double retval = read_float_internal(data);
645645
if (unlikely(retval == CPY_FLOAT_ERROR && PyErr_Occurred())) {
@@ -660,14 +660,14 @@ write_float_internal(PyObject *data, double value) {
660660
}
661661

662662
static PyObject*
663-
write_float(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames) {
664-
static const char * const kwlist[] = {"data", "value", 0};
665-
static CPyArg_Parser parser = {"OO:write_float", kwlist, 0};
666-
PyObject *data;
667-
PyObject *value;
668-
if (unlikely(!CPyArg_ParseStackAndKeywordsSimple(args, nargs, kwnames, &parser, &data, &value))) {
663+
write_float(PyObject *self, PyObject *const *args, size_t nargs) {
664+
if (unlikely(nargs != 2)) {
665+
PyErr_Format(PyExc_TypeError,
666+
"write_float() takes exactly 2 arguments (%zu given)", nargs);
669667
return NULL;
670668
}
669+
PyObject *data = args[0];
670+
PyObject *value = args[1];
671671
_CHECK_WRITE_BUFFER(data, NULL)
672672
if (unlikely(!PyFloat_Check(value))) {
673673
PyErr_SetString(PyExc_TypeError, "value must be a float");
@@ -735,13 +735,13 @@ read_int_internal(PyObject *data) {
735735
}
736736

737737
static PyObject*
738-
read_int(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames) {
739-
static const char * const kwlist[] = {"data", 0};
740-
static CPyArg_Parser parser = {"O:read_int", kwlist, 0};
741-
PyObject *data;
742-
if (unlikely(!CPyArg_ParseStackAndKeywordsOneArg(args, nargs, kwnames, &parser, &data))) {
738+
read_int(PyObject *self, PyObject *const *args, size_t nargs) {
739+
if (unlikely(nargs != 1)) {
740+
PyErr_Format(PyExc_TypeError,
741+
"read_int() takes exactly 1 argument (%zu given)", nargs);
743742
return NULL;
744743
}
744+
PyObject *data = args[0];
745745
_CHECK_READ_BUFFER(data, NULL)
746746
CPyTagged retval = read_int_internal(data);
747747
if (unlikely(retval == CPY_INT_TAG)) {
@@ -841,14 +841,14 @@ write_int_internal(PyObject *data, CPyTagged value) {
841841
}
842842

843843
static PyObject*
844-
write_int(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames) {
845-
static const char * const kwlist[] = {"data", "value", 0};
846-
static CPyArg_Parser parser = {"OO:write_int", kwlist, 0};
847-
PyObject *data;
848-
PyObject *value;
849-
if (unlikely(!CPyArg_ParseStackAndKeywordsSimple(args, nargs, kwnames, &parser, &data, &value))) {
844+
write_int(PyObject *self, PyObject *const *args, size_t nargs) {
845+
if (unlikely(nargs != 2)) {
846+
PyErr_Format(PyExc_TypeError,
847+
"write_int() takes exactly 2 arguments (%zu given)", nargs);
850848
return NULL;
851849
}
850+
PyObject *data = args[0];
851+
PyObject *value = args[1];
852852
_CHECK_WRITE_BUFFER(data, NULL)
853853
if (unlikely(!PyLong_Check(value))) {
854854
PyErr_SetString(PyExc_TypeError, "value must be an int");
@@ -876,13 +876,13 @@ read_tag_internal(PyObject *data) {
876876
}
877877

878878
static PyObject*
879-
read_tag(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames) {
880-
static const char * const kwlist[] = {"data", 0};
881-
static CPyArg_Parser parser = {"O:read_tag", kwlist, 0};
882-
PyObject *data;
883-
if (unlikely(!CPyArg_ParseStackAndKeywordsOneArg(args, nargs, kwnames, &parser, &data))) {
879+
read_tag(PyObject *self, PyObject *const *args, size_t nargs) {
880+
if (unlikely(nargs != 1)) {
881+
PyErr_Format(PyExc_TypeError,
882+
"read_tag() takes exactly 1 argument (%zu given)", nargs);
884883
return NULL;
885884
}
885+
PyObject *data = args[0];
886886
_CHECK_READ_BUFFER(data, NULL)
887887
uint8_t retval = read_tag_internal(data);
888888
if (unlikely(retval == CPY_LL_UINT_ERROR && PyErr_Occurred())) {
@@ -899,14 +899,14 @@ write_tag_internal(PyObject *data, uint8_t value) {
899899
}
900900

901901
static PyObject*
902-
write_tag(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames) {
903-
static const char * const kwlist[] = {"data", "value", 0};
904-
static CPyArg_Parser parser = {"OO:write_tag", kwlist, 0};
905-
PyObject *data;
906-
PyObject *value;
907-
if (unlikely(!CPyArg_ParseStackAndKeywordsSimple(args, nargs, kwnames, &parser, &data, &value))) {
902+
write_tag(PyObject *self, PyObject *const *args, size_t nargs) {
903+
if (unlikely(nargs != 2)) {
904+
PyErr_Format(PyExc_TypeError,
905+
"write_tag() takes exactly 2 arguments (%zu given)", nargs);
908906
return NULL;
909907
}
908+
PyObject *data = args[0];
909+
PyObject *value = args[1];
910910
_CHECK_WRITE_BUFFER(data, NULL)
911911
uint8_t unboxed = CPyLong_AsUInt8(value);
912912
if (unlikely(unboxed == CPY_LL_UINT_ERROR && PyErr_Occurred())) {
@@ -941,18 +941,18 @@ WriteBuffer_type_internal(void) {
941941
};
942942

943943
static PyMethodDef librt_internal_module_methods[] = {
944-
{"write_bool", (PyCFunction)write_bool, METH_FASTCALL | METH_KEYWORDS, PyDoc_STR("write a bool")},
945-
{"read_bool", (PyCFunction)read_bool, METH_FASTCALL | METH_KEYWORDS, PyDoc_STR("read a bool")},
946-
{"write_str", (PyCFunction)write_str, METH_FASTCALL | METH_KEYWORDS, PyDoc_STR("write a string")},
947-
{"read_str", (PyCFunction)read_str, METH_FASTCALL | METH_KEYWORDS, PyDoc_STR("read a string")},
948-
{"write_bytes", (PyCFunction)write_bytes, METH_FASTCALL | METH_KEYWORDS, PyDoc_STR("write bytes")},
949-
{"read_bytes", (PyCFunction)read_bytes, METH_FASTCALL | METH_KEYWORDS, PyDoc_STR("read bytes")},
950-
{"write_float", (PyCFunction)write_float, METH_FASTCALL | METH_KEYWORDS, PyDoc_STR("write a float")},
951-
{"read_float", (PyCFunction)read_float, METH_FASTCALL | METH_KEYWORDS, PyDoc_STR("read a float")},
952-
{"write_int", (PyCFunction)write_int, METH_FASTCALL | METH_KEYWORDS, PyDoc_STR("write an int")},
953-
{"read_int", (PyCFunction)read_int, METH_FASTCALL | METH_KEYWORDS, PyDoc_STR("read an int")},
954-
{"write_tag", (PyCFunction)write_tag, METH_FASTCALL | METH_KEYWORDS, PyDoc_STR("write a short int")},
955-
{"read_tag", (PyCFunction)read_tag, METH_FASTCALL | METH_KEYWORDS, PyDoc_STR("read a short int")},
944+
{"write_bool", (PyCFunction)write_bool, METH_FASTCALL, PyDoc_STR("write a bool")},
945+
{"read_bool", (PyCFunction)read_bool, METH_FASTCALL, PyDoc_STR("read a bool")},
946+
{"write_str", (PyCFunction)write_str, METH_FASTCALL, PyDoc_STR("write a string")},
947+
{"read_str", (PyCFunction)read_str, METH_FASTCALL, PyDoc_STR("read a string")},
948+
{"write_bytes", (PyCFunction)write_bytes, METH_FASTCALL, PyDoc_STR("write bytes")},
949+
{"read_bytes", (PyCFunction)read_bytes, METH_FASTCALL, PyDoc_STR("read bytes")},
950+
{"write_float", (PyCFunction)write_float, METH_FASTCALL, PyDoc_STR("write a float")},
951+
{"read_float", (PyCFunction)read_float, METH_FASTCALL, PyDoc_STR("read a float")},
952+
{"write_int", (PyCFunction)write_int, METH_FASTCALL, PyDoc_STR("write an int")},
953+
{"read_int", (PyCFunction)read_int, METH_FASTCALL, PyDoc_STR("read an int")},
954+
{"write_tag", (PyCFunction)write_tag, METH_FASTCALL, PyDoc_STR("write a short int")},
955+
{"read_tag", (PyCFunction)read_tag, METH_FASTCALL, PyDoc_STR("read a short int")},
956956
{"cache_version", (PyCFunction)cache_version, METH_NOARGS, PyDoc_STR("cache format version")},
957957
{NULL, NULL, 0, NULL}
958958
};

0 commit comments

Comments
 (0)