[Python-ideas] Fwd: Define a method or function attribute outside of a class with the dot operator
steve at pearwood.info
Fri Feb 10 06:51:59 EST 2017
On Fri, Feb 10, 2017 at 10:05:30PM +1100, Chris Angelico wrote:
> * What would the __name__ be? In "def ham.spam():", is the name "spam"
> or "ham.spam"?
"spam" of course, just like it is now:
py> class Ham:
... def spam(self):
You might be thinking of __qualname__:
> Or say you have "def x():" - is the name "x" or
> something else?
I wouldn't allow that. I feel that "any assignment target at all" is an
over-generalisation, a case of YAGNI.
It is relatively easy to change our mind and add additional cases in the
future, but very difficult to remove them if they turn out to be a
My intuition tells me that we should allow :
def name dot name (args):
possibly even more than one dot:
def name dot name dot name ... (args):
but no additional cases:
# syntax error
def spamfunction(): ...
More information about the Python-ideas