> Nobody said it cannot be done the way you did it. You were just pointed at the shortcomings of your approach
I "addressed" the shortcomings of "my approach" by showing that Python (the language, not the community) allows you to access and manipulate the data you claimed was important and missing.
I don't believe it is necessary for most simple functions to know what their name is. I do believe the demonstrated code is self documenting enough to not require a documentation string. You made those "requirements". I never claimed that every function must be a lambda - you seem to be implying I am, so I am explicitly stating that I do not.
Here's a place where you really do need a named function (due to deficiencies in Python's lambda implementation):
>>> def named_lambda(procedure, name, documentation=''):
... procedure.__name__ = '<lambda {}>'.format(name)
... procedure.__doc__ = documentation
... return procedure
...
>>> absolute_path = named_lambda(lambda path: path if path.startswith('/') else '/' + path, 'absolute_path', 'Return the absolute unix path from a given path name')
>>> absolute_path.__name__
'<lambda absolute_path>'
>>> absolute_path.__doc__
'Return the absolute unix path from a given path name'
Of course, that's completely silly... since the point of a lambda function generally is that the function is generally small enough and short-lived enough that it does not need a name or documentation.
> the Python community generally prefers stupidly simple, easy to understand solutions.
Which, despite your protests, includes using lambdas!
> Using magic attributes to argue against it just makes it worse - remember this is a thread about idiomatic Python code bases.
How else does a function "know its own name" unless it uses the "magic" attribute "__name__"? Oh, you prefer "func_name"? That's cute:
So in this comment I am replying to, it is a bad thing that I made use of "__name__", but in the comment THAT was replying to, it was a bad thing that I did NOT use "__name__" or its linked "func_name". That's how you move goal posts!
> Nobody said it cannot be done the way you did it. You were just pointed at the shortcomings of your approach
I "addressed" the shortcomings of "my approach" by showing that Python (the language, not the community) allows you to access and manipulate the data you claimed was important and missing.
I don't believe it is necessary for most simple functions to know what their name is. I do believe the demonstrated code is self documenting enough to not require a documentation string. You made those "requirements". I never claimed that every function must be a lambda - you seem to be implying I am, so I am explicitly stating that I do not.
Here's a place where you really do need a named function (due to deficiencies in Python's lambda implementation):
Of course, that's completely silly... since the point of a lambda function generally is that the function is generally small enough and short-lived enough that it does not need a name or documentation.> the Python community generally prefers stupidly simple, easy to understand solutions.
Which, despite your protests, includes using lambdas!
> Using magic attributes to argue against it just makes it worse - remember this is a thread about idiomatic Python code bases.
How else does a function "know its own name" unless it uses the "magic" attribute "__name__"? Oh, you prefer "func_name"? That's cute:
So in this comment I am replying to, it is a bad thing that I made use of "__name__", but in the comment THAT was replying to, it was a bad thing that I did NOT use "__name__" or its linked "func_name". That's how you move goal posts!