-
Notifications
You must be signed in to change notification settings - Fork 2
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
Improve disable_init
docs and export the metaclass
#55
Conversation
Signed-off-by: Leandro Lucarella <[email protected]>
This effectively make it public. We need this in case users want to combine the metaclass with other metaclasses, like `abc.ABCMeta`. Signed-off-by: Leandro Lucarella <[email protected]>
The new recommendation actually doesn't work. The correct way to do it would be: ```py super(cls, self).__init__() ``` But this is not even necessary when you are applying the decorator to a simple class that doesn't inherit from anything (i.e. inherits from `object` directly). Applying the decorators to other sub-classes, is much trickier than just addint the `super()` call, so we will just not recommend or support doing that and keep the usage documentation simple. This reverts commit 073b921. Signed-off-by: Leandro Lucarella <[email protected]>
e7161b8
to
f1a8db6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request improves the documentation for the disable_init decorator and exports the NoInitConstructibleMeta metaclass. Key changes include updating docstrings and examples to clarify the use of the metaclass, removing unnecessary calls to super().init(self) in factory methods, and adjusting keyword arguments handling in error generation functions.
Comments suppressed due to low confidence (1)
src/frequenz/core/typing.py:176
- [nitpick] The documentation example uses 'meta' to specify the metaclass. Consider using the standard 'metaclass' keyword (i.e. 'class MyClass(metaclass=NoInitConstructibleMeta):') for clarity, if that is supported in your context.
class MyClass(meta=NoInitConstructibleMeta):
Improve the docs to point out that disabling the `__init__` for existing classes via a sub-class is complicated, so it is only recommended to use both the decorator and metaclass on classes inheriting from `object` directly. Also improve the documentation of `NoInitConstructibleMeta` to be more complete and give an example on using with `abc.ABCMeta`. Signed-off-by: Leandro Lucarella <[email protected]>
f1a8db6
to
cb4c104
Compare
Improve the docs to point out that disabling the
__init__
for existing classes via a sub-class is complicated, so it is only recommended to use both the decorator and metaclass on classes inheriting fromobject
directly.Also make
NoInitConstructibleMeta
public (remove the_
prefix from the name) and improve its documentation to be more complete and give an example on using withabc.ABCMeta
.