Search code examples
pythonpyside2deprecation-warningqtablewidgetitem

Deprecation warning in Python, does it make sense here?


I'm writing a Python (using 3.8.2 version) app for my project. In the app I use PySide2 to create QTableWidget object called items_tableWidget. Here's the fragment of my code, which creates QTableWidgetItem objects, fills them with my data, makes them not editable by user and puts them into the table:

cell = QtWidgets.QTableWidgetItem()
cell.setData(Qt.DisplayRole, data)
cell.setFlags(cell.flags() & ~Qt.ItemIsEditable)
ui.items_tableWidget.setItem(row_number, column_number, cell)

I get this warning when running the code:

C:\Users\Deronek\Documents\Qt\SkyblockBazaar\main.py:346: DeprecationWarning: an integer is required (got type PySide2.QtCore.Qt.ItemFlags).  Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python.
  cell.setFlags(cell.flags() & ~Qt.ItemIsEditable)

I am a newbie to Python, but I think this warning doesn't make sense, because setFlags argument, as well as flags() return value and ItemIsEditable enum value all have defined types and operators in Qt namespace, so I am not performing an implict conversion. Am I right or I am missing something?

Thank you for your answers.


Solution

  • In Python 3.8 there has been the following change:

    Constructors of int, float and complex will now use the __index__() special method, if available and the corresponding method __int__(), __float__() or __complex__() is not available. (Contributed by Serhiy Storchaka in bpo-20092.)

    And PySide2 uses the ints to map the enumerations and it has already been reported PYSIDE-1226. And as they point out in the comments in the next release, that warning will no longer be released.

    In general you shouldn't have a problem and just get that annoying warning.