<div dir="ltr">I think the proposal, so far, seems to confuse two separate things. One is attaching a method to a class after definition. The second is attaching a method to an instance after creation. Or at least it is unclear to me which of those is the intention, since both seem to occur in the examples. Or maybe it's both, but those feel like fairly different use cases.<div><br></div><div>Which is to say, we really need a PEP. As it stands, I'm somewhere around -0.75 on the idea.</div><div><br></div><div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="auto"><div dir="auto"> @decorate(MyClass)</div><div dir="auto"> def MyClass.method(self, other: MyClass) -> List[MyClass]:</div></div></div></blockquote><div><br></div><div>In this case, the syntax is 100% superfluous. One can simply write:</div><div><br></div></div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div class="gmail_extra"><div class="gmail_quote"><div> @decorate(MyClass)</div></div></div></div><div><div class="gmail_extra"><div class="gmail_quote"><div> def method(self, other: MyClass) -> List[MyClass]:</div><div><br></div></div></div></div></blockquote><div><div class="gmail_extra"><div class="gmail_quote"><div>The class is already mentioned in the decorator. If the intention is to add the method to the class, that's fine, and something a decorator can do. Perhaps the spelling for this decorator-factory could be `enhance`. Or more verbosely `inject_method`. Spelling aside, the syntax adds nothing.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="auto"><div dir="auto"> my_menu = Menu(['Pizza', 'Cake', 'Pasta'])<br></div><div> def my_menu.select_callback(item_i<wbr>ndex):</div><div> if item_index == 0: # Pizza</div><div> serve_food(pizza)</div><div> else: # Cake or Pasta</div><div> ...</div></div></div></blockquote><div><br></div><div>Attaching to the instance is fine too. But I prefer the current spelling so far:</div><div><br></div></div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div class="gmail_extra"><div class="gmail_quote"><div><div>my_menu1 = Menu(['Pizza', 'Cake', 'Pasta'])</div></div></div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div class="gmail_extra"><div class="gmail_quote"><div>my_menu2 = Menu(...)</div></div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div class="gmail_extra"><div class="gmail_quote"><div><br></div></div></div></div><div><div class="gmail_extra"><div class="gmail_quote"><div><div>def callback1(self, ...):</div></div></div></div></div><div><div class="gmail_extra"><div class="gmail_quote"><div><div> ...</div></div><div><div><div class="gmail_extra"><div class="gmail_quote">def callback2(self, ...):</div></div></div><div><div class="gmail_extra"><div class="gmail_quote"> ...</div><div class="gmail_quote"><br></div></div></div><div><div class="gmail_extra"><div class="gmail_quote"><div></div></div></div></div></div></div></div></div><div><div class="gmail_extra"><div class="gmail_quote"><div><div>my_menu1.callback = callback2</div></div></div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div class="gmail_extra"><div class="gmail_quote"><div>my_menu2.callback = callback1</div></div></div></div></blockquote><div><div class="gmail_extra"><div class="gmail_quote"><div><div> </div></div><div>Under the current approach, you can flexibly define callbacks outside of the scope of any particular instance or class, and attach them as needed to instances. Obviously the new syntax would not *remove* this option, but it would cover only a narrow subset of what we can already do... and the way we do it now feels much better self-documenting as to intent.</div><div><br></div><div>Yours, David...</div></div><div><br></div>-- <br><div class="gmail_signature">Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons. Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div>
</div></div></div>