Annotate subclass's method?
Annotate subclass's method?
Suppose I have a Mixin class Mixin
, and a method a
in this class uses another method b
which will be in another Base
class. I want to annotate b
in class Mixin
so that I can take the advantages of inspection.
Mixin
a
b
Base
b
Mixin
The real usage is multiple inherition. I create a mixin for tornado.web.RequestHandler
, and the subclass could inherit both RequestHandler
and Mixin
to get some useful functions.
tornado.web.RequestHandler
RequestHandler
Mixin
As far as I know, I can annotate b
as Callable
, but I cannot annotate its signature.
b
Callable
class Base
def b():
# do something
class Mixin:
b: Callable # not enough, losing signature.
#b: RequestHandler.b # not work, still losing signature.
def a():
# call b here.
class subclass(Base, Mixin):
pass
BTW, I'm using Pycharm.
@RamazanPolat It isn't related to subclass but only baseclass. I need to use function
b
in function a
, and I hope pycharm can inspect b
's signature while I am writing a
.– Sraw
Jun 29 at 9:06
b
a
b
a
AFAIU, in Base class, a method named A will call another method called B. The method B will be defined in a subclass of Base. Is this correct?
– Ramazan Polat
2 days ago
Do you mean that
b
in subclasses could have different signatures or they are always same?– user2235698
2 days ago
b
Guys, see my update. Sorry for confusion.
– Sraw
2 days ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Are you trying to annotate the subclass method or attribute?
– Ramazan Polat
Jun 29 at 9:02