Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/frequenz/core/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def disable_init(
as the class is parsed by the Python interpreter. It will also raise a `TypeError`
when the `__init__` method is called.

To create an instance you must provide a factory method, using `__new__`.
To create an instance you must provide a factory method, using `__new__` to create
the instance and calling `super().__init__(self)` explicitly to initialize it.

Warning:
This decorator will use a custom metaclass to disable the `__init__` constructor
Expand All @@ -64,6 +65,7 @@ class MyClass:
@classmethod
def new(cls, value: int = 1) -> Self:
self = cls.__new__(cls)
super().__init__(self)
self.value = value
return self

Expand Down Expand Up @@ -100,7 +102,9 @@ def __init__(self) -> None:
class MyClass:
@classmethod
def new(cls) -> Self:
return cls.__new__(cls)
self = cls.__new__(cls)
super().__init__(self)
return self

try:
instance = MyClass()
Expand Down
Loading