Alfred Krohmer added the comment:
> I'd expect a TypeError because of the extra cls argument. It's already a
> bound method.
Sorry, that was a typo.
> Consider making a playlist class that *has* a SQL table, not one that *is* a
> SQL table, i.e. use composition instead of inheritance. That sidesteps the
> incompatible metaclasses.
That would be indeed a solution, but not for the original problem.
I think I have an example now that makes my point clear.
The following code works as it should:
import traceback
import sys
class MyMeta(type):
def __setattr__(cls, key, value):
print("OK")
class MyClass(metaclass=MyMeta):
pass
MyClass.abc = 12 # outputs "OK"
try:
print(MyClass.abc)
except:
traceback.print_exc(file=sys.stdout) # exception comes here as expected
type.__setattr__(MyClass, 'test', 42) # outputs nothing
print(MyClass.test) # outputs "42"
If I get this right, this should be **valid code** (and it should **not** be a
bug, that this actually works).
However, above define MyMeta like following:
from PyQt5.QtMultimedia import QMediaPlaylist
class MyMeta(type(QMediaPlaylist)):
def __setattr__(cls, key, value):
print("OK")
And you get:
TypeError: can't apply this __setattr__ to PyQt5.QtCore.pyqtWrapperType object
I think that this actually **is** unexpected behaviour. I'm **not** trying to
apply __setattr__ to PyQt5.QtCore.pyqtWrapperType but to MyClass!
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue23276>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com