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) # 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 ``` We need to override class-construction without allowing `__init__` to run a second time. This introduces a simple metaclass to allow overriding the behavior of `RisingEdge.__call__(...)`
- Loading branch information
1 parent
435f7c9
commit c293c99
Showing
2 changed files
with
48 additions
and
6 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