[ParamSpec] Duplicating the signature from one method to another method in ABC #1474
Unanswered
randolf-scholz
asked this question in
Q&A
Replies: 1 comment
-
Some related issues: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Consider that we have some abstract base class
The default implementation of
logpdf
is likely not useful when a subclass decides to add optional arguments. Instead we might want to do something like:However, this would mean that subclasses really do have to always allow
*args
and**kwargs
. What we really want to say is that the signature oflogpdf
has to be identical topdf
. (So something likedef logpdf(self, x: ArrayLike, /, *args: P.args, **kwargs: P.kwargs)
whereP
is aParamSpec
bound toself.pdf
)Maybe one could do some wrapper trickery in
__init_subclass__
, but that seems complicated. Is there any way to directly tell type checkers the intention here?Beta Was this translation helpful? Give feedback.
All reactions