forked from cocotb/cocotb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a regression introduced in cocotbgh-727 and cocotbgh-723, caused …
…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) B = SomeClass(1) ``` We need to override class-construction without allowing `__init__` to run a second time. One option would be to just remove `__init__` entirely, and move the contents into `__new__`. The other option, which I take in this patch, is to introduce a metaclass overriding the `__call__` operator on class types. I'm not convinced this is the best approach, but it does fix the problem.
- Loading branch information
1 parent
1c35b8d
commit 1ebf47a
Showing
3 changed files
with
66 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters