<div dir="ltr">Hi all,<div><br></div><div>I would like to add one more generic remark about syntax extensions, regarding something</div><div>Markus said and which has bothered me before, also related to other syntax proposals. </div><div><br></div><div><span style="font-size:12.8px">"Decorator approach is no different from doing `Foo.bar = bar` under the function definition I think, except it requires one to figure out what the decorator does first."</span><br></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">My point would be that the new syntax *also* requires one to figure out what the new syntax does.</span></div><div><span style="font-size:12.8px">And unfortunately, syntax is much less discoverable than decorators.</span></div><div><span style="font-size:12.8px">For a decorator, I can do `help(decorator)' or search the python library reference or probably</span></div><div><span style="font-size:12.8px">just mouse-hover over the name in my favourite editor/IDE.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">But if I don't understand the dot in `class foo.bar:', then what?</span></div><div><span style="font-size:12.8px">It's probably somewhere buried in the language spec for `class' but realistically</span></div><div><span style="font-size:12.8px">I am now going to blight Stackoverflow with my questions.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Stephan</span></div><div class="gmail_extra"><br><div class="gmail_quote">2017-02-10 13:13 GMT+01:00 Joao S. O. Bueno <span dir="ltr"><<a href="mailto:jsbueno@python.org.br" target="_blank">jsbueno@python.org.br</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I am definetelly -1 to this idea.<br>
<br>
But since you are discussing this seriously, one nice thing is to<br>
recall how Javascript does that:<br>
`function <name> () ` is an expression that returns the created<br>
function, and thus can be assigned to anything on<br>
the left side.<br>
<br>
Of course, that would throw us back to a way of thinking of inline<br>
definition of multiline functions -<br>
which is another requested and unresolved thing in Python.<br>
<br>
(But we might require the `def` statement to still be aligned, at<br>
least style-wise, and require<br>
people to write<br>
<br>
Foo.foo =\<br>
def (self, ...): ...<br>
<br>
)<br>
<br>
That said, this possibility in Javascript is the source of severe<br>
inconsistencies in how functions are declared across different<br>
libraries and projects, and IMHO, makes reading (and writting) a real pain.<br>
<br>
(And, as stated above, a two line decorator could make for the patching -<br>
it does not need to have such an ugly name as "monkey_patch" - it<br>
could be just "assign" instead)<br>
<br>
js<br>
-><-<br>
<div class="gmail-HOEnZb"><div class="gmail-h5"><br>
On 10 February 2017 at 09:51, Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br>
> On Fri, Feb 10, 2017 at 10:05:30PM +1100, Chris Angelico wrote:<br>
><br>
>> * What would the __name__ be? In "def ham.spam():", is the name "spam"<br>
>> or "ham.spam"?<br>
><br>
> "spam" of course, just like it is now:<br>
><br>
> py> class Ham:<br>
> ... def spam(self):<br>
> ... ...<br>
> ...<br>
> py><br>
> py> Ham.spam.__name__<br>
> 'spam'<br>
><br>
><br>
> You might be thinking of __qualname__:<br>
><br>
> py> Ham.spam.__qualname__<br>
> 'Ham.spam'<br>
><br>
><br>
>> Or say you have "def x[0]():" - is the name "x[0]" or<br>
>> something else?<br>
><br>
> I wouldn't allow that. I feel that "any assignment target at all" is an<br>
> over-generalisation, a case of YAGNI.<br>
><br>
> It is relatively easy to change our mind and add additional cases in the<br>
> future, but very difficult to remove them if they turn out to be a<br>
> mistake.<br>
><br>
> My intuition tells me that we should allow :<br>
><br>
> def name dot name (args):<br>
><br>
> possibly even more than one dot:<br>
><br>
> def name dot name dot name ... (args):<br>
><br>
><br>
> but no additional cases:<br>
><br>
> # syntax error<br>
> def spam[0]function(): ...<br>
><br>
><br>
><br>
><br>
> --<br>
> Steve<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>
______________________________<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>
</div></div></blockquote></div><br></div></div>