- Notifications
You must be signed in to change notification settings - Fork263
How to refer to the class-type ofself
, without bound TypeVars?#2029
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 inpyright playground fromcollections.abcimportSequenceclassExpr:defsimplify(self)->"Expr": ...classExprSequence[E:Expr](Sequence[E],Expr):def__init__(self,exprs:list[E])->None: ...defsimplify(self)->Expr:returnself.__class__([e.simplify()foreinself])# ❌# "list[Expr]" cannot be assigned to list[E] Inside a method like I am not looking for |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 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.
-
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 |
BetaWas this translation helpful?Give feedback.