Skip to content

Commit 317240f

Browse files
committed
ENH: Removing obsolete python2 support
`#ifndef PY3K` conditionals and related logic Removal of PY3k ifdef ifndef not done correctly.
1 parent 2fde0d7 commit 317240f

11 files changed

+10
-257
lines changed

src/PythonQt.cpp

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,13 @@ void PythonQt::init(int flags, const QByteArray& pythonQtModuleName)
101101
_self->_p->_pySourcelessFileLoader = importlib.getVariable("SourcelessFileLoader");
102102
}
103103

104-
#ifdef PY3K
105104
PythonQtObjectPtr asyncio;
106105
asyncio.setNewRef(PyImport_ImportModule("asyncio"));
107106
if (asyncio)
108107
{
109108
_self->_p->_pyEnsureFuture = asyncio.getVariable("ensure_future");
110109
_self->_p->_pyFutureClass = asyncio.getVariable("Future");
111110
}
112-
#endif
113111

114112
PythonQt::priv()->setupSharedLibrarySuffixes();
115113

@@ -336,11 +334,8 @@ PythonQt::PythonQt(int flags, const QByteArray& pythonQtModuleName)
336334
_p->_initFlags = flags;
337335

338336
if ((flags & PythonAlreadyInitialized) == 0) {
339-
#ifdef PY3K
340337
Py_SetProgramName(const_cast<wchar_t*>(L"PythonQt"));
341-
#else
342-
Py_SetProgramName(const_cast<char*>("PythonQt"));
343-
#endif
338+
344339
if (flags & IgnoreSiteModule) {
345340
// this prevents the automatic importing of Python site files
346341
Py_NoSiteFlag = 1;
@@ -430,7 +425,6 @@ void PythonQtPrivate::setTaskDoneCallback(const PythonQtObjectPtr & callable)
430425
PythonQtObjectPtr PythonQtPrivate::checkAndRunCoroutine(const PythonQtObjectPtr& object)
431426
{
432427
PythonQtObjectPtr result;
433-
#ifdef PY3K
434428
if (!PyCoro_CheckExact(object))
435429
{
436430
return result;
@@ -453,9 +447,6 @@ PythonQtObjectPtr PythonQtPrivate::checkAndRunCoroutine(const PythonQtObjectPtr&
453447
Py_XDECREF(methodName);
454448
}
455449
Py_XDECREF(args);
456-
#else
457-
Q_UNUSED(object)
458-
#endif
459450
return result;
460451
}
461452

@@ -989,11 +980,7 @@ QVariant PythonQt::evalCode(PyObject* object, PyObject* pycode) {
989980
}
990981
PyObject* r = nullptr;
991982
if (dict) {
992-
#ifdef PY3K
993983
r = PyEval_EvalCode(pycode, globals, dict);
994-
#else
995-
r = PyEval_EvalCode((PyCodeObject*)pycode, globals, dict);
996-
#endif
997984
}
998985
if (r) {
999986
result = PythonQtConv::PyObjToQVariant(r);
@@ -1253,14 +1240,7 @@ QStringList PythonQt::introspectObject(PyObject* object, ObjectType type)
12531240
keys = PyDict_Keys(object);
12541241
isDict = true;
12551242
} else {
1256-
#if defined(MEVISLAB) && !defined(PY3K)
1257-
int oldPy3kWarningFlag = Py_Py3kWarningFlag;
1258-
Py_Py3kWarningFlag = 0; // temporarily disable Python 3 warnings
1259-
keys = PyObject_Dir(object);
1260-
Py_Py3kWarningFlag = oldPy3kWarningFlag;
1261-
#else
12621243
keys = PyObject_Dir(object);
1263-
#endif
12641244
}
12651245
if (keys) {
12661246
int count = PyList_Size(keys);
@@ -1296,9 +1276,6 @@ QStringList PythonQt::introspectObject(PyObject* object, ObjectType type)
12961276
&& value->ob_type != &PyModule_Type
12971277
&& value->ob_type != &PyType_Type
12981278
&& value->ob_type != &PythonQtSlotFunction_Type
1299-
#ifndef PY3K
1300-
&& value->ob_type != &PyClass_Type
1301-
#endif
13021279
) {
13031280
results << keystr;
13041281
}
@@ -1647,13 +1624,8 @@ int custom_system_exit_exception_handler()
16471624
// return exitcode;
16481625

16491626
PyErr_Fetch(&exception, &value, &tb);
1650-
#ifndef PY3K
1651-
if (Py_FlushLine()) {
1652-
PyErr_Clear();
1653-
}
1654-
#else
1627+
16551628
// TODO: unclear what to do, since Py_FlushLine is gone...
1656-
#endif
16571629
fflush(stdout);
16581630
if (value == nullptr || value == Py_None)
16591631
goto done;
@@ -1831,7 +1803,6 @@ static PyMethodDef PythonQtMethods[] = {
18311803
{nullptr, nullptr, 0, nullptr}
18321804
};
18331805

1834-
#ifdef PY3K
18351806
static PyModuleDef PythonQtModuleDef = {
18361807
PyModuleDef_HEAD_INIT,
18371808
"",
@@ -1843,20 +1814,15 @@ static PyModuleDef PythonQtModuleDef = {
18431814
nullptr,
18441815
nullptr
18451816
};
1846-
#endif
18471817

18481818
void PythonQt::initPythonQtModule(bool redirectStdOut, const QByteArray& pythonQtModuleName)
18491819
{
18501820
QByteArray name = "PythonQt";
18511821
if (!pythonQtModuleName.isEmpty()) {
18521822
name = pythonQtModuleName;
18531823
}
1854-
#ifdef PY3K
18551824
PythonQtModuleDef.m_name = name.constData();
18561825
_p->_pythonQtModule = PyModule_Create(&PythonQtModuleDef);
1857-
#else
1858-
_p->_pythonQtModule = Py_InitModule(name.constData(), PythonQtMethods);
1859-
#endif
18601826
_p->_pythonQtModuleName = name;
18611827

18621828
Py_INCREF((PyObject*)&PythonQtBoolResult_Type);
@@ -1892,13 +1858,11 @@ void PythonQt::initPythonQtModule(bool redirectStdOut, const QByteArray& pythonQ
18921858
}
18931859
Py_XDECREF(old_module_names);
18941860

1895-
#ifdef PY3K
18961861
PyObject* modulesAttr = PyObject_GetAttrString(sys.object(), "modules");
18971862
PyObject* pyUnicodeObject = PyUnicode_FromString(name.constData());
18981863
PyDict_SetItem(modulesAttr, pyUnicodeObject, _p->_pythonQtModule.object());
18991864
Py_XDECREF(modulesAttr);
19001865
Py_XDECREF(pyUnicodeObject);
1901-
#endif
19021866
}
19031867

19041868
QString PythonQt::getReturnTypeOfWrappedMethod(PyObject* module, const QString& name)
@@ -2232,9 +2196,6 @@ bool PythonQtPrivate::isMethodDescriptor(PyObject* object) const
22322196
!PyObject_HasAttrString(object, "__set__") &&
22332197
!PyMethod_Check(object) &&
22342198
!PyFunction_Check(object)
2235-
#ifndef PY3K
2236-
&& !PyClass_Check(object)
2237-
#endif
22382199
) {
22392200
return true;
22402201
}
@@ -2596,20 +2557,12 @@ void PythonQtPrivate::shellClassDeleted( void* shellClass )
25962557

25972558
PyObject* PythonQtPrivate::wrapMemoryAsBuffer( const void* data, Py_ssize_t size )
25982559
{
2599-
#ifdef PY3K
26002560
return PyMemoryView_FromMemory((char*)data, size, PyBUF_READ);
2601-
#else
2602-
return PyBuffer_FromMemory((char*)data, size);
2603-
#endif
26042561
}
26052562

26062563
PyObject* PythonQtPrivate::wrapMemoryAsBuffer( void* data, Py_ssize_t size )
26072564
{
2608-
#ifdef PY3K
26092565
return PyMemoryView_FromMemory((char*)data, size, PyBUF_WRITE);
2610-
#else
2611-
return PyBuffer_FromReadWriteMemory((char*)data, size);
2612-
#endif
26132566
}
26142567

26152568
PythonQtClassInfo* PythonQtPrivate::getClassInfo( const QMetaObject* meta )

src/PythonQt.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,9 @@ typedef QObject* PythonQtQObjectCreatorFunctionCB();
147147
template<class T> QObject* PythonQtCreateObject() { return new T(); }
148148

149149
//! Helper define to convert from QString to Python C-API
150-
#ifdef PY3K
151150
#define QStringToPythonConstCharPointer(arg) ((arg).toUtf8().constData())
152151
#define QStringToPythonCharPointer(arg) ((arg).toUtf8().data())
153152
#define QStringToPythonEncoding(arg) ((arg).toUtf8())
154-
#else
155-
#define QStringToPythonConstCharPointer(arg) ((arg).toLatin1().constData())
156-
#define QStringToPythonCharPointer(arg) ((arg).toLatin1().data())
157-
#define QStringToPythonEncoding(arg) ((arg).toLatin1())
158-
#endif
159153

160154
//! The main interface to the Python Qt binding, realized as a singleton
161155
/*!

src/PythonQtBoolResult.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ static PyNumberMethods PythonQtBoolResult_as_number = {
6969
nullptr, /* nb_add */
7070
nullptr, /* nb_subtract */
7171
nullptr, /* nb_multiply */
72-
#ifndef PY3K
73-
nullptr, /* nb_divide */
74-
#endif
7572
nullptr, /* nb_remainder */
7673
nullptr, /* nb_divmod */
7774
nullptr, /* nb_power */
@@ -85,22 +82,12 @@ static PyNumberMethods PythonQtBoolResult_as_number = {
8582
nullptr, /* nb_and */
8683
nullptr, /* nb_xor */
8784
nullptr, /* nb_or */
88-
#ifndef PY3K
89-
nullptr, /* nb_coerce */
90-
#endif
9185
nullptr, /* nb_int */
9286
nullptr, /* nb_long / nb_reserved in Py3K */
9387
nullptr, /* nb_float */
94-
#ifndef PY3K
95-
nullptr, /* nb_oct */
96-
nullptr, /* nb_hex */
97-
#endif
9888
nullptr, /* nb_inplace_add */
9989
nullptr, /* nb_inplace_subtract */
10090
nullptr, /* nb_inplace_multiply */
101-
#ifndef PY3K
102-
nullptr, /* nb_inplace_divide */
103-
#endif
10491
nullptr, /* nb_inplace_remainder */
10592
nullptr, /* nb_inplace_power */
10693
nullptr, /* nb_inplace_lshift */
@@ -112,9 +99,7 @@ static PyNumberMethods PythonQtBoolResult_as_number = {
11299
nullptr, /* nb_true_divide */
113100
nullptr, /* nb_inplace_floor_divide */
114101
nullptr, /* nb_inplace_true_divide */
115-
#ifdef PY3K
116102
nullptr, /* nb_index in Py3K */
117-
#endif
118103
};
119104

120105
PyTypeObject PythonQtBoolResult_Type = {
@@ -155,4 +140,3 @@ PyTypeObject PythonQtBoolResult_Type = {
155140
0, /* tp_dictoffset */
156141
(initproc)&PythonQtBoolResult_init, /* tp_init */
157142
};
158-

src/PythonQtClassWrapper.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,6 @@ static void initializeSlots(PythonQtClassWrapper* wrap)
260260
wrap->_base.as_number.nb_multiply = (binaryfunc)PythonQtInstanceWrapper_mul;
261261
}
262262
if (typeSlots & PythonQt::Type_Divide) {
263-
#ifndef PY3K
264-
wrap->_base.as_number.nb_divide = (binaryfunc)PythonQtInstanceWrapper_div;
265-
#endif
266263
wrap->_base.as_number.nb_true_divide = (binaryfunc)PythonQtInstanceWrapper_div;
267264
}
268265
if (typeSlots & PythonQt::Type_And) {
@@ -294,9 +291,6 @@ static void initializeSlots(PythonQtClassWrapper* wrap)
294291
wrap->_base.as_number.nb_inplace_multiply = (binaryfunc)PythonQtInstanceWrapper_imul;
295292
}
296293
if (typeSlots & PythonQt::Type_InplaceDivide) {
297-
#ifndef PY3K
298-
wrap->_base.as_number.nb_inplace_divide = (binaryfunc)PythonQtInstanceWrapper_idiv;
299-
#endif
300294
wrap->_base.as_number.nb_inplace_true_divide = (binaryfunc)PythonQtInstanceWrapper_idiv;
301295
}
302296
if (typeSlots & PythonQt::Type_InplaceAnd) {
@@ -321,11 +315,7 @@ static void initializeSlots(PythonQtClassWrapper* wrap)
321315
wrap->_base.as_number.nb_invert = (unaryfunc)PythonQtInstanceWrapper_invert;
322316
}
323317
if (typeSlots & PythonQt::Type_NonZero) {
324-
#ifdef PY3K
325318
wrap->_base.as_number.nb_bool = (inquiry)PythonQtInstanceWrapper_nonzero;
326-
#else
327-
wrap->_base.as_number.nb_nonzero = (inquiry)PythonQtInstanceWrapper_nonzero;
328-
#endif
329319
}
330320
}
331321
}
@@ -564,11 +554,7 @@ static PyObject *PythonQtClassWrapper_getattro(PyObject *obj, PyObject *name)
564554
}
565555

566556
// look for the internal methods (className(), help())
567-
#ifdef PY3K
568557
PyObject* internalMethod = PyObject_GenericGetAttr(obj, name);
569-
#else
570-
PyObject* internalMethod = Py_FindMethod( PythonQtClassWrapper_methods, obj, (char*)attributeName);
571-
#endif
572558
if (internalMethod) {
573559
return internalMethod;
574560
}
@@ -635,11 +621,7 @@ PyTypeObject PythonQtClassWrapper_Type = {
635621
0, /* tp_weaklistoffset */
636622
nullptr, /* tp_iter */
637623
nullptr, /* tp_iternext */
638-
#ifdef PY3K
639624
PythonQtClassWrapper_methods, /* tp_methods */
640-
#else
641-
nullptr, /* tp_methods */
642-
#endif
643625
nullptr, /* tp_members */
644626
nullptr, /* tp_getset */
645627
nullptr, /* tp_base */
@@ -654,4 +636,3 @@ PyTypeObject PythonQtClassWrapper_Type = {
654636
};
655637

656638
//-------------------------------------------------------
657-

0 commit comments

Comments
 (0)