[pygobject] Fix commit 168a087 for Python 3
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Fix commit 168a087 for Python 3
- Date: Mon, 7 May 2012 01:20:26 +0000 (UTC)
commit a3329539291bd8ea9aa6cb184a05ea7c21f8885a
Author: Martin Pitt <martinpitt gnome org>
Date: Sun May 6 18:19:35 2012 -0700
Fix commit 168a087 for Python 3
Simplify the type check and use the already existing one. Fix the string check
to work with both Python 2 and 3.
gi/pygi-argument.c | 42 +++++++++---------------------------------
1 files changed, 9 insertions(+), 33 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index ca88911..ec31d55 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -728,14 +728,9 @@ _pygi_argument_from_object (PyObject *object,
{
PyObject *int_;
- if (!PyObject_TypeCheck (object, &PyInt_Type) &&
- !PyObject_TypeCheck (object, &PyLong_Type)) {
- PyErr_SetString (PyExc_TypeError, "expected int or long argument");
- break;
- }
-
int_ = PYGLIB_PyNumber_Long (object);
if (int_ == NULL) {
+ PyErr_SetString (PyExc_TypeError, "expected int argument");
break;
}
@@ -758,14 +753,9 @@ _pygi_argument_from_object (PyObject *object,
PyObject *number;
guint64 value;
- if (!PyObject_TypeCheck (object, &PyInt_Type) &&
- !PyObject_TypeCheck (object, &PyLong_Type)) {
- PyErr_SetString (PyExc_TypeError, "expected int or long argument");
- break;
- }
-
number = PYGLIB_PyNumber_Long (object);
if (number == NULL) {
+ PyErr_SetString (PyExc_TypeError, "expected int argument");
break;
}
@@ -794,14 +784,9 @@ _pygi_argument_from_object (PyObject *object,
PyObject *number;
gint64 value;
- if (!PyObject_TypeCheck (object, &PyInt_Type) &&
- !PyObject_TypeCheck (object, &PyLong_Type)) {
- PyErr_SetString (PyExc_TypeError, "expected int or long argument");
- break;
- }
-
number = PYGLIB_PyNumber_Long (object);
if (number == NULL) {
+ PyErr_SetString (PyExc_TypeError, "expected int argument");
break;
}
@@ -822,15 +807,9 @@ _pygi_argument_from_object (PyObject *object,
{
PyObject *float_;
- if (!PyObject_TypeCheck (object, &PyFloat_Type) &&
- !PyObject_TypeCheck (object, &PyInt_Type) &&
- !PyObject_TypeCheck (object, &PyLong_Type)) {
- PyErr_SetString (PyExc_TypeError, "expected float or int argument");
- break;
- }
-
float_ = PyNumber_Float (object);
if (float_ == NULL) {
+ PyErr_SetString (PyExc_TypeError, "expected float or int argument");
break;
}
@@ -843,15 +822,9 @@ _pygi_argument_from_object (PyObject *object,
{
PyObject *float_;
- if (!PyObject_TypeCheck (object, &PyFloat_Type) &&
- !PyObject_TypeCheck (object, &PyInt_Type) &&
- !PyObject_TypeCheck (object, &PyLong_Type)) {
- PyErr_SetString (PyExc_TypeError, "expected float or int argument");
- break;
- }
-
float_ = PyNumber_Float (object);
if (float_ == NULL) {
+ PyErr_SetString (PyExc_TypeError, "expected float or int argument");
break;
}
@@ -985,7 +958,10 @@ _pygi_argument_from_object (PyObject *object,
/* Note, strings are sequences, but we cannot accept them here */
if (!PySequence_Check (object) ||
- PyString_Check (object) || PyUnicode_Check (object)) {
+#if PY_VERSION_HEX < 0x03000000
+ PyString_Check (object) ||
+#endif
+ PyUnicode_Check (object)) {
PyErr_SetString (PyExc_TypeError, "expected sequence");
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]