Movatterモバイル変換


[0]ホーム

URL:


[Python-ideas] Fwd: Define a method or function attributeoutsideof a class with the dot operator

Paul Moorep.f.moore at gmail.com
Sun Feb 12 12:49:43 EST 2017


On 12 February 2017 at 16:51, Markus Meskanen <markusmeskanen at gmail.com> wrote:>> I will say, though, that you're right that we've over-reacted a bit to>> the monkeypatching use case. Although maybe that's because no-one can>> think of many *other* use cases that they'd need the new syntax for>> :-)> Hi Paul, I believe at least two other use cases than monkey patching have> been mentioned already:My point was that people couldn't think of use cases *they* would needthe syntax for. Personally, I'd never use the new syntax for the 2examples you gave. I don't know if your examples are from real-worldcode, but they feel artificial to me (the callback one less so, butpeople have been using callbacks for years without missing thissyntax).This is just one example of using it to set an instance's variable toa callback. It's just shorthand for:>   def select_callback(item_index):>       ...>   my_menu.select_callback = select_callback> This reads much easierThat's personal opinion, and there's a lot of disagreement on this point.> and saves us from typing the same thing three times> (see decorators).That's an objective benefit, sure. I don't think it's major in itself,but that's just *my* opinion :-) You could of course use a shortername for the function, if it matters to you (it doesn't *have* to bethe same as the attribute name).Anyway, let's wait for a PEP that addresses all of the points raisedin this thread.Paul


More information about the Python-ideasmailing list

[8]ページ先頭

©2009-2026 Movatter.jp