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
Python3: incompatible metaclass syntax #8652
Comments
@six.add_metaclass looks way cleaner to me. See also this thread on stack overflow. |
cc @josephsl |
Thinking about this, I propose fixing this as part of #8393. |
@six.add_metaclass fails for NVDAObject: log snippetCRITICAL - __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. |
Hi, 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). Thanks. |
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.
Py2: syntax
metaclass = xxx
Py3 syntax
class A(metalcass=xxx):
We need "six" module to make metaclass run in Python2 and 3.
There are two tools in that module.
Which one is more suitable?
six.with_metaclass(metaclass, *bases)
or
@six.add_metaclass(metaclass)
The text was updated successfully, but these errors were encountered: