Skip to content
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

Alternative #2 to gh-733, fixing spurious warnings. #742

Closed

Conversation

eric-wieser
Copy link
Member

For the sake of simplicity, this commit undoes the merger between the factory functions and the classes themselves, while keeping the weakref behavior.

In future, it would be good to explore the more complex approach taken in gh-733, which ensures that isinstance(Join(), Join), which this patch does not.
Since this property was not true before gh-723 and gh-727 anyway, we can afford to revert that improvement in order to get a release out the door.

@eric-wieser eric-wieser changed the title Alternative #3 to gh-733, fixing spurious warnings. Alternative #2 to gh-733, fixing spurious warnings. Jan 7, 2019
@eric-wieser eric-wieser force-pushed the rollback-type-and-factory-merge branch from fde9fc8 to 1dd0964 Compare January 8, 2019 08:23
…by a misunderstanding of how __new__ works

In those patches, I declared classes that were roughly
```python
class SomeClass:
    def __new__(cls, arg):
        try:
            return existing[arg]
        except KeyError:
            return super(SomeClass, cls).__new__(cls, arg)

    def __init__(self, arg):
        self.arg = arg
        self.state = 0
```

This approach has a fatal flaw (cocotbgh-729), with function calls shown in the following code:
```python
A = SomeClass(1)
# SomeClass.__new__(SomeClass, 1) -> A
# A.__init__(1)
B = SomeClass(1)
# SomeClass.__new__(SomeClass, 1) -> A   # reusing the existing instance
# A.__init__(1)  # uh oh, we reset A.state
```

For the sake of simplicity, this commit undoes the merger between the factory functions and the classes themselves, while keeping the weakref behavior.

In future, it would be good to explore the more complex approach taken in cocotbgh-733, which ensures that `isinstance(Join(), Join)`, which this patch does not.
Since this property was not true before cocotbgh-723 and cocotbgh-727 anyway, we can afford to revert that improvement in order to get a release out the door.
@eric-wieser eric-wieser force-pushed the rollback-type-and-factory-merge branch from 1dd0964 to 957340e Compare January 8, 2019 16:41
@imphil
Copy link
Member

imphil commented Jan 8, 2019

We took #733 now, thanks for your fantastic work @eric-wieser! It's really rare to see so much dedication at work; be sure to ask for a $PREFERRED_DRINK if we ever meet at a conference or elsewhere.

@imphil imphil closed this Jan 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants