-
-
Notifications
You must be signed in to change notification settings - Fork 80
Support declaring a Parameterized class as an ABC #1031
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1031 +/- ##
==========================================
- Coverage 88.12% 87.93% -0.19%
==========================================
Files 9 9
Lines 4857 4875 +18
==========================================
+ Hits 4280 4287 +7
- Misses 577 588 +11 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Looks good to me!
The only thing I want to see before this is merged are some tests making sure the decorators used to declare abstract methods, properties etc. work as expected.
In an ideal world we would run the whole test suite again using ParameterizedABC to check everything else works but that seems overkill, especially as this base class is opt-in.
|
@jlstevens I have added some tests and updated the documentation. I also added |
| "- Added in version 2.3.0, an abstract Parameterized class can be created by inheriting from `ParameterizedABC`, which is equivalent as inheriting from `ABC` from the Python [abc](https://docs.python.org/3/library/abc.html) module.\n", | ||
| "- A Parameterized class can be annotated with the class attribute `__abstract` set to `True` to declare it as abstract.\n", | ||
| "\n", | ||
| "We recommend adopting the first approach that is more generic and powerful. The second approach is specific to Param (`inspect.isabstract(class)` won't return `True` for example) and preserved for compatibility reasons.\n", |
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.
Maybe it is worth adding a follow on sentence to strongly recommend not mixing approaches? Having two inconsistent ways of checking if a class is abstract sounds like a recipe for confusion!
That said, maybe param could have a wrapper utility that tries inspect.isabstract(class) first and if that returns False, checks again the param way?
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.
Comment added in ce27b13
That said, maybe param could have a wrapper utility that tries inspect.isabstract(class) first and if that returns False, checks again the param way?
Internally, we have the _is_abstract function that does exactly that. I don't really want to make it public though:
- Parameterized classes have an
abstractproperty (that's documented too, I checked) that accounts for both approaches - The less public API the better
- Ultimately, the goal would be to deprecate and remove the old abstract way
If people feel strongly about it, we can add it in another release anyway.
|
The additional tests and documentation as well as the import change all look good to me! Made one comment to address but otherwise happy to approve and see this merge once the tests and issue merging to |
Param has its own way of declaring "abstract" classes by annotating them with
__abstract = True. Parameterized classes all have anabstractproperty inherited from the metaclass that returns whether this attribute (mangled) was set. Theconcrete_descendentsfunction uses_is_abstractto build a collection of the non-abstract descendents only. #84 suggests replacing this approach by Abstract Bases Classes. This MR doesn't replace the current mechanism (we'd need to deprecate it first) but instead attempts to add support to ABCs, allowing users to declare a Parameterized ABC.To avoid metaclass conflicts, it introduces the
ParameterizedABCclass that users must inherit from when they want to declare an ABC.@sdc50 I know your comment on #84 dates a little (5 years :) ). If you're still interested in this feature, let me know what you think about it. On the HoloViz code bases side, I think we'll need to see whether we can effectively replace
__abstract = True.