Late-bound argument defaults for Python should focus on the source scope
Late-bound argument defaults for Python should focus on the source scope
Posted Nov 18, 2021 16:12 UTC (Thu) by ccurtis (guest, #49713)Parent article: Late-bound argument defaults for Python
I like the "@" syntax ("&" would also work for me), but the function signature proposed seems fundamentally flawed. In this statement:
The x=x parameter uses global x as the default. The y=x parameter uses the local x as the default. We can live with that difference. We *need* that difference in behaviour, otherwise these examples won't work:This comment implies that a "global x" exists and so means a finer-grained specification is warranted. If true, this seems a much better approach:def method(self, x=>self.attr) # @x=self.attr def bisect(a, x, lo=0, hi=>len(a)) # @hi=len(a)
def method(self, x=self.attr+@self.attr) # 'self' is global self, '@self' is the local selfThat said, I know nothing more about Python than what I just read and I don't expect Van Rossum to be reading this, but if it makes sense someone may want to mention it on the list. It is the RHS scope that is of interest...