Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch METH_VARGS to METH_O #679

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions pendulum/parsing/_iso8601.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,15 @@ static int FixedOffset_init(FixedOffset *self, PyObject *args, PyObject *kwargs)
* def utcoffset(self, dt):
* return timedelta(seconds=self.offset * 60)
*/
static PyObject *FixedOffset_utcoffset(FixedOffset *self, PyObject *args) {
static PyObject *FixedOffset_utcoffset(FixedOffset *self, PyObject *dt) {
return PyDelta_FromDSU(0, self->offset, 0);
}

/*
* def dst(self, dt):
* return timedelta(seconds=self.offset * 60)
*/
static PyObject *FixedOffset_dst(FixedOffset *self, PyObject *args) {
static PyObject *FixedOffset_dst(FixedOffset *self, PyObject *dt) {
return PyDelta_FromDSU(0, self->offset, 0);
}

Expand All @@ -223,7 +223,7 @@ static PyObject *FixedOffset_dst(FixedOffset *self, PyObject *args) {
* sign = '-'
* return f"{sign}{self.offset / 60}:{self.offset % 60}"
*/
static PyObject *FixedOffset_tzname(FixedOffset *self, PyObject *args) {
static PyObject *FixedOffset_tzname(FixedOffset *self, PyObject *dt) {
if (self->tzname != NULL) {
return PyUnicode_FromString(self->tzname);
}
Expand Down Expand Up @@ -264,9 +264,9 @@ static PyMemberDef FixedOffset_members[] = {
* Class methods
*/
static PyMethodDef FixedOffset_methods[] = {
{"utcoffset", (PyCFunction)FixedOffset_utcoffset, METH_VARARGS, ""},
{"dst", (PyCFunction)FixedOffset_dst, METH_VARARGS, ""},
{"tzname", (PyCFunction)FixedOffset_tzname, METH_VARARGS, ""},
{"utcoffset", (PyCFunction)FixedOffset_utcoffset, METH_O, ""},
{"dst", (PyCFunction)FixedOffset_dst, METH_O, ""},
{"tzname", (PyCFunction)FixedOffset_tzname, METH_O, ""},
{NULL}
};

Expand Down Expand Up @@ -512,8 +512,8 @@ Parsed* new_parsed() {

/* -------------------------- Functions --------------------------*/

Parsed* _parse_iso8601_datetime(char *str, Parsed *parsed) {
char* c;
Parsed* _parse_iso8601_datetime(const char *str, Parsed *parsed) {
const char* c;
int monthday = 0;
int week = 0;
int weekday = 1;
Expand Down Expand Up @@ -927,8 +927,8 @@ Parsed* _parse_iso8601_datetime(char *str, Parsed *parsed) {
}


Parsed* _parse_iso8601_duration(char *str, Parsed *parsed) {
char* c;
Parsed* _parse_iso8601_duration(const char *str, Parsed *parsed) {
const char* c;
int value = 0;
int grabbed = 0;
int in_time = 0;
Expand Down Expand Up @@ -1205,20 +1205,23 @@ Parsed* _parse_iso8601_duration(char *str, Parsed *parsed) {
}


PyObject* parse_iso8601(PyObject *self, PyObject *args) {
char* str;
PyObject* parse_iso8601(PyObject *self, PyObject *dtstr) {
const char* str;
PyObject *obj;
PyObject *tzinfo;
Py_ssize_t len;

Parsed *parsed = new_parsed();

if (!PyArg_ParseTuple(args, "s", &str)) {
PyErr_SetString(
PyExc_ValueError, "Invalid parameters"
);
if (!PyUnicode_Check(dtstr)) {
PyErr_SetString(PyExc_ValueError,
"Invalid parameters");
free(parsed);
return NULL;
}

str = PyUnicode_AsUTF8AndSize(dtstr, &len);

if (*str == 'P') {
// Duration (or interval)
if (_parse_iso8601_duration(str, parsed) == NULL) {
Expand Down Expand Up @@ -1300,7 +1303,7 @@ static PyMethodDef helpers_methods[] = {
{
"parse_iso8601",
(PyCFunction) parse_iso8601,
METH_VARARGS,
METH_O,
PyDoc_STR("Parses a ISO8601 string into a tuple.")
},
{NULL}
Expand Down