How to refer to the class-type of self
, without bound TypeVars?
#2029
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 |
Beta Was this translation helpful? Give feedback.
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 ofself
withoutE
being already bound? Bothmypy
andpyright
infer 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.Beta Was this translation helpful? Give feedback.
All reactions