Movatterモバイル変換


[0]ホーム

URL:


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

Random832random832 at fastmail.com
Sat Feb 11 15:17:41 EST 2017


On Sat, Feb 11, 2017, at 00:33, Greg Ewing wrote:> Chris Angelico wrote:> > Which is why these proposals always seem to gravitate to "anything you> > can assign to",>> There might be some parsing difficulties with that, e.g.>>     def foo(x)[5](y, z):>        ...>> That should be acceptable, because foo(x)[5] is something> assignable, but foo(x) looks like the beginning of the> definition of a function called foo. I'm not sure whether> the parser would cope with that.We could require parentheses to be used anywhere the grammar otherwisecouldn't handle it, like yielding a tuple from a generator expression.def (whatever)(args):This does raise the question though of what the function's name/qualnamewould be. It's cosmetic, but it's also the only real difference betweendef and an assignment *now*, so it's worth considering. In the casewhere the last element of the expression is an attribute, the name wouldsimply be the attribute, but would the class portion of the qualname(and the name when it's not an attribute) need to depend on the runtimevalue of what is being assigned, or would it simply use a string ofexactly "foo(x)[5]"?


More information about the Python-ideasmailing list

[8]ページ先頭

©2009-2026 Movatter.jp