Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Python3: incompatible metaclass syntax #8652
Metaclass is used in several places in NVDA code. Python3 changed the syntax of using a metaclass and it is not compatible with python 2.
We need "six" module to make metaclass run in Python2 and 3.
@six.add_metaclass fails for NVDAObject:
CRITICAL - __main__ (15:19:51.082): core failure Traceback (most recent call last): File "nvda.pyw", line 214, in core.main() File "core.py", line 223, in main import appModuleHandler File "appModuleHandler.py", line 27, in import NVDAHelper File "NVDAHelper.py", line 19, in import eventHandler File "eventHandler.py", line 9, in import api File "api.py", line 11, in import review File "review.py", line 10, in from NVDAObjects import NVDAObject, NVDAObjectTextInfo File "NVDAObjects\__init__.py", line 146, in class NVDAObject(documentBase.TextContainerObject,baseObject.ScriptableObject): File "d:\development\nvda\source repo\include\wxPython\six.py", line 847, in wrapper return metaclass(cls.__name__, cls.__bases__, orig_vars) File "baseObject.py", line 72, in __init__ raise TypeError("%s is already a class attribute, cannot create descriptor with methods %s"%(x,methodsString)) TypeError: columnCount is already a class attribute, cannot create descriptor with methods
with_metaclass works ok.
referenced this issue
Aug 22, 2018
Update: my experiment shows that Python 3 approach is way superior, and with that, we don't have to worry about which six.meta* function to use. Besides, using native method looks way cleaner and also allows getters and setters to work properly by adding metaclass declaration when declaring classes. However, because we want to provide easy means of transition, I propose that #8393 be the venue for tackling this also, and come back to this once transition is taking place (leaving this open for now).