[Python-ideas] Fwd: Define a method or function attribute outside of a class with the dot operator
Nick Coghlan
ncoghlan at gmail.com
Fri Feb 10 09:16:17 EST 2017
On 10 February 2017 at 12:16, Chris Angelico <rosuav at gmail.com> wrote:
> On Fri, Feb 10, 2017 at 10:13 PM, Paul Moore <p.f.moore at gmail.com> wrote:
>> Furthermore, once we open up this possibility, I would expect requests
>> for things like
>>
>> func_table = {}
>> func_table["foo"] = lambda a, b: a+b
>> def func_table["bar"] (a,b):
>> return a-b
>>
>> pretty quickly. How would you respond to those? (Setting up function
>> tables is a much more common and reasonable need than monkeypatching
>> classes).
>
> Which is why these proposals always seem to gravitate to "anything you
> can assign to", which is at least easy enough to explain. All your
> examples would be completely acceptable.under that system.
But what do __name__ and __qualname__ get set to?
What happens if you do this at class scope, rather than at module
level or inside another function?
What happens to the zero-argument super() support at class scope?
What happens if you attempt to use zero-argument super() when *not* at
class scope?
These are *answerable* questions (and injecting the right __class__
cell reference for zero-argument super() support is a compelling
technical argument in favour of this feature over ordinary attribute
binding operations), but there's a lot more to the proposal than just
relaxing a syntactic restriction in the language grammar.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list