abstractmethod signal intended function signatures #1082
Replies: 1 comment
-
I don't see any reason why your Similarly, "must have at least 1 positional arg" doesn't make sense to me. How would you call such function? By passing it 1 argument, in which case it won't work if it takes more than 1 argument? I think there's currently no way to say "this method must exist, but it can accept or not accept whatever arguments it wants". There's some discussion here: python/mypy#5876 Currently the best you can do is Slightly unrelated: I often wish it was possible to separate "you get this when you explicitly inherit from this ABC" from "this functionality is required for conforming to this ABC". For example, here's discussion about how |
Beta Was this translation helpful? Give feedback.
-
I seem to encounter the following problem: When creating ABC's sometimes I want
@abstractmethod
s to have a specific signature, sometimes I want to allow subclass to have arbitrary signatures, and sometimes I want something in-between.Here is an example of what I am talking about; Note that this not violate LSP, as ABCs cannot be instantiated.
In particular, when I write an example, then
Then
__call__
has the wrong signaturedownload
has the wrong signature (cf. False positivearguments-differ
with defaults pylint-dev/pylint#5338, Allow adding parameters in an overridden method, without trippingarguments-differ
pylint-dev/pylint#1556)Am I missing something, or is it currently not possible to properly type hint ABCs? A possible solution I could see is if it were possible to annotate the signature of
@abstractmethods
, for example withEllipsis
.These checks could be used by static code checkers to verify signatures of subclasses and be ignored at runtime.
Beta Was this translation helpful? Give feedback.
All reactions