How to refer to the class-type of self, without bound TypeVars?
#2029
Unanswered
randolf-scholz
asked this question in
Q&A
Replies: 1 comment
|
You can probably annotate You are giving up some type safety, especially in the latter case, but that already goes out of the window to some degree due to the implicit reliance on You could even try to use a method-scoped |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Code sample in pyright playground
Inside a method like
def simplify(self), how can I refer to the runtime type oftype(self), i.e. the class ofselfwithoutEbeing already bound? Bothmypyandpyrightinfer bothtype(self)andself.__class__essentially astype[typing.Self], which leads to the typing error in the example above.I am not looking for
ExprSequence([e.simplify() for e in self]), because this has different runtime behavior.All reactions