Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Is Borg really implemented right ? #3

Copy link
Copy link
@jpic

Description

@jpic
Issue body actions

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.