Message234390
> 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! |
|
Date |
User |
Action |
Args |
2015-01-20 20:26:45 | devkid | set | recipients:
+ devkid, eryksun |
2015-01-20 20:26:45 | devkid | set | messageid: <1421785605.6.0.132050401564.issue23276@psf.upfronthosting.co.za> |
2015-01-20 20:26:45 | devkid | link | issue23276 messages |
2015-01-20 20:26:45 | devkid | create | |
|