<div dir="ltr">But if people are gonna do it anyways with the tools provided (monkey patching), why not provide them with better tools? And this wouldn't only be for classes, but for setting instance attributes too (see the Menu example in original mail).<div><br></div><div>- Markus</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 10, 2017 at 5:38 PM, Steve Dower <span dir="ltr"><<a href="mailto:steve.dower@python.org" target="_blank">steve.dower@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div style="font-family:Calibri,sans-serif;font-size:11pt">Since votes seem to be being counted and used for debate purposes, I am -1 to anything that encourages or condones people adding functionality to classes outside of the class definition. (Monkeypatching in my mind neither condones or encourages, and most descriptions come with plenty of caveats about how it should be avoided.)<br><br>My favourite description of object-oriented programming is that it's like "reading a road map through a drinking(/soda/pop) straw". We do not need to tell people that it's okay to make this problem worse by providing first-class tools to do it.<br><br>Top-posted from my Windows Phone</div></div><div dir="ltr"><hr><span style="font-family:Calibri,sans-serif;font-size:11pt;font-weight:bold">From: </span><span style="font-family:Calibri,sans-serif;font-size:11pt"><a href="mailto:rosuav@gmail.com" target="_blank">Chris Angelico</a></span><br><span style="font-family:Calibri,sans-serif;font-size:11pt;font-weight:bold">Sent: </span><span style="font-family:Calibri,sans-serif;font-size:11pt">2/10/2017 8:27</span><br><span style="font-family:Calibri,sans-serif;font-size:11pt;font-weight:bold">To: </span><span style="font-family:Calibri,sans-serif;font-size:11pt"><a href="mailto:python-ideas@python.org" target="_blank">Python-Ideas</a></span><br><span style="font-family:Calibri,sans-serif;font-size:11pt;font-weight:bold">Subject: </span><span style="font-family:Calibri,sans-serif;font-size:11pt">Re: [Python-ideas] Fwd: Define a method or function attributeoutside of a class with the dot operator</span><br><br></div><div><div class="h5">On Sat, Feb 11, 2017 at 1:16 AM, Nick Coghlan <<a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>> wrote:<br>> But what do __name__ and __qualname__ get set to?<br>><br>> What happens if you do this at class scope, rather than at module<br>> level or inside another function?<br>><br>> What happens to the zero-argument super() support at class scope?<br>><br>> What happens if you attempt to use zero-argument super() when *not* at<br>> class scope?<br>><br>> These are *answerable* questions...<br><br>... and are exactly why I asked the OP to write up a PEP. This isn't<br>my proposal, so it's not up to me to make the decisions.<br><br>For what it's worth, my answers would be:<br><br>__name__ would be the textual representation of exactly what you typed<br>between "def" and the open parenthesis. __qualname__ would be built<br>the exact same way it currently is, based on that __name__.<br><br>Zero-argument super() would behave exactly the way it would if you<br>used a simple name. This just changes the assignment, not the creation<br>of the function. So if you're inside a class, you could populate a<br>lookup dictionary with method-like functions. Abuse this, and you're<br>only shooting your own foot.<br><br>Zero-argument super() outside of a class, just as currently, would be<br>an error. (Whatever kind of error it currently is.)<br><br>Maybe there are better answers to these questions, I don't know.<br>That's what the PEP's for.<br><br>ChrisA<br>______________________________<wbr>_________________<br>Python-ideas mailing list<br><a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br><a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br></div></div></div><br>______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br></blockquote></div><br></div>