This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gone
Recipients gone
Date 2017-08-26.09:14:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1503738862.98.0.13501343613.issue31283@psf.upfronthosting.co.za>
In-reply-to
Content
I discovered this while messing about with an unrelated idea, but the issue is that if you inherit explicitly from object, you get different behaviour than when you inherit implicitly. This is duplicated from my SO answer here: https://stackoverflow.com/questions/1238606/is-it-necessary-or-useful-to-inherit-from-pythons-object-in-python-3-x/45893772#45893772

If you explicitly inherit from object, what you are actually doing is inheriting from builtins.object regardless of what that points to at the time.

Therefore, I could have some (very wacky) module which overrides object for some reason. We'll call this first module "newobj.py":

import builtins

old_object = builtins.object  # otherwise cyclic dependencies

class new_object(old_object):

    def __init__(self, *args, **kwargs):
        super(new_object, self).__init__(*args, **kwargs)
        self.greeting = "Hello World!" 

builtins.object = new_object  #overrides the default object
Then in some other file ("klasses.py"):

class Greeter(object):
    pass

class NonGreeter:
    pass
Then in a third file (which we can actually run):

import newobj, klasses  # This order matters!

greeter = klasses.Greeter()
print(greeter.greeting)  # prints the greeting in the new __init__

non_greeter = NonGreeter()
print(non_greeter.greeting) # throws an attribute error
So you can see that, in the case where it is explicitly inheriting from object, we get a different behaviour than where you allow the implicit inheritance.
History
Date User Action Args
2017-08-26 09:14:23gonesetrecipients: + gone
2017-08-26 09:14:22gonesetmessageid: <1503738862.98.0.13501343613.issue31283@psf.upfronthosting.co.za>
2017-08-26 09:14:22gonelinkissue31283 messages
2017-08-26 09:14:21gonecreate