jfhbrook / pyee

A rough port of Node.js's EventEmitter to Python with a few tricks of its own
https://github.com/jfhbrook/public
MIT License
371 stars 39 forks source link

Inherit from object to allow easier inheritance of EventEmitter #32

Closed LivInTheLookingGlass closed 7 years ago

LivInTheLookingGlass commented 7 years ago

Right now I need to inherit from both EventEmitter and object if I want to build off of your class.

If you inherit from object, then I don't need to manage multiple inheritance. It's the difference between

class Example(EventEmitter, object):
    def __init__(self):
        """This is gross, and can cause MRO errors"""
        object.__init__(self)
        EventEmitter.__init__(self)

and

class Example(EventEmitter):
    def __init__(self):
        """This is cleaner, and the recommended style"""
        super(example, self).__init__()
LivInTheLookingGlass commented 7 years ago

Probably the biggest problem is that using the other inheritance order doesn't actually work at all. In Python3, this will raise an Exception on import:

class Example(object, EventEmitter):
    def __init__(self):
        """This is gross, and can cause MRO errors"""
        object.__init__(self)
        EventEmitter.__init__(self)
jfhbrook commented 7 years ago

Good catch! I'm surprised I wasn't already inheriting from object.

Maybe not critical, but how would you feel about adding a test for inheritance?

LivInTheLookingGlass commented 7 years ago

Sure. Shouldn't be too hard.

On February 7, 2017 5:20:49 PM EST, Joshua Holbrook notifications@github.com wrote:

Good catch! I'm surprised I wasn't already inheriting from object.

Maybe not critical, but how would you feel about adding a test for inheritance?

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/jfhbrook/pyee/pull/32#issuecomment-278161240

LivInTheLookingGlass commented 7 years ago

Tests now passing. Tests that object and EventEmitter are in the MRO, and tests that it can still instantiate after a lengthy inheritance chain.

jfhbrook commented 7 years ago

Released in 3.0.2 !

LivInTheLookingGlass commented 7 years ago

Thanks!