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
Assignment to __bases__ of direct object subclasses #37817
Comments
|
I'm not entirely sure this is a bug, but I think it is Python 2.3a1 (#38, Dec 31 2002, 17:53:59) [MSC
v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more
information.
>>> class A(object):
... pass
...
>>> class B(object):
... pass
...
>>> B.__bases__ = (A,)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: __bases__ assignment: 'A' deallocator differs
from 'object'It seems like you should be able to change the |
|
Logged In: YES I agree this is a bit surprising. When I was writing this It certainly may be that I've overdone it. In this case I It also happens that my motivating use-case for this isn't I don't understand your last, parenthetical, comment. You might be right that we don't need to worry about |
|
Logged In: YES Sorry about the parenthetical comment; I think what I was trying As for use cases, I don't have any myself (I ran into this with |
|
Logged In: YES Are you interested in working up a patch for this? Hacking |
|
Logged In: YES Well, I wrote a small patch which I'm attaching. However, I |
|
Logged In: YES Mhmm. That looks OK to me (after realizing that solid_base But I don't know how one can be sure :-( |
|
Logged In: YES Two years on, I think about this again. Still here? :) The motivating thought is that: class A(object): pass
class B(object): pass
B.__bases__ = (A,)and class A(object): pass
class B(A): passshould be equivalent. An issue that hadn't occurred to me before is that in the first example both |
|
Logged In: YES Still here -- sorry not to reply sooner. I couldn't It seems to me nobody is particularly troubled by this |
|
Logged In: YES Well, my motivation is to better understand what's going on I'm now fairly confident that the line This issue in and of itself isn't that high a priority, but |
|
Is anyone still working on this? It seems like an oddity of python that I've found that i am able to bypass this problem by creating the class object(object):passHowever, this feels like an ugly hack. |
|
Another 3 and a bit years on <wink> I still think my comment I'm not at all likely to work on this any time soon myself. |
|
in my project i need to be able to let the user dynamically make and class object(object):
passtrick seems to work, but i can't really oversee the consequenses. I also A= type("A", (object,), {'one': 1})
B= type("B", (object,), {'two': 2})
C= type("C", (object,), {'three': 3})
A = type("A",(A,B),{})
print dir(A)
print A.__bases__
print '-----------------------------------'
A.__bases__ = (B,C)
print dir(A)
print A.__bases__
print '-----------------------------------'no exceptions, but the second dir(A) shows that A has lost its attribute if the class object(object) trick is not safe, is there a way to get the |
|
Lars, I think that your question has a simple explanation, and is not
The instruction "A = type(...)" causes A to refer to another object; it |
|
ok, i see what you mean, for me at this time the most important question class object(object)
passdo, why can i change baseclasses after i redeclare object this way, and cheers |
|
I just hit up on this same bug and the "class object(object): pass" workaround worked fine. I too would like to know how safe this workaround is, could someone more insightful please comment on this? |
|
I too just found the same issue, dunno if it was settled on as being a bug per se. "class object(object): pass" Also worked for me. I don't feel great about doing that though. So I opted for more verbose name as not to collide with "object" I have to wonder, since it's been 9 years, if all of us finding this issue are guilty of doing it wrong =) |
|
Has any work been done on typeobject.c to render this obsolete? Failing that are there any souls brave enough to take on typeobject.c? |
|
I understand Michael's comment http://bugs.python.org/issue672115#msg14169 but I'm failing to see how it's directly related to this issue: as Michael himself said it's even relevant for the object-subclass-object hack or for any hierarchy whatsoever. Is the comment warning about the entire writable-bases idea? It feels to me like the behavior should be consistently extended or consistently banned, but currently some cases work, another cases don't, and there seems to be no clear rationale supporting this state of affairs. Am I wrong? |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: