Skip to content

Is Borg really implemented right ? #3

@jpic

Description

@jpic

I thought that the point of Borg was to allow subclassing. However, the implementation doesn't match expectations in this case:

class Borg:
    __shared_state = {}

    def __init__(self):
        self.__dict__ = self.__shared_state
        self.state = 'Running'

    def __str__(self):
        return self.state

instance0 = Borg()
instance1 = Borg()

instance0.state = 'Idle'

print instance1  # prints 'Idle', instead of 'Running', as expected

borg = Borg()
borg.state = 'Idle'


class YourBorg(Borg):
    pass

borg = YourBorg()
print borg  # prints 'Running' instead of 'Idle', **not** as expected

Are you sure that Borg supports setting attributes in the constructor ?

It looks like it defeats the purpose of Borg...

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions