[Python-ideas] YAML (yet-another-multiline-lambda)
Andrew Barnert
abarnert at yahoo.com
Wed Oct 23 09:53:13 CEST 2013
On Oct 22, 2013, at 11:07, Steven D'Aprano <steve at pearwood.info> wrote:
> On Tue, Oct 22, 2013 at 09:27:59AM -0700, Andrew Barnert wrote:
>> On Oct 22, 2013, at 5:39, Steven D'Aprano <steve at pearwood.info> wrote:
>>
>>> On Tue, Oct 22, 2013 at 03:10:29AM -0700, Antony Lee wrote:
>>>
>>>> Specifically, I suggest that the "def" (and possibly the "class")
>>>> keyword(s) may be used in an expression context, if immediately surrounded
>>>> by parentheses.
>>>
>>> I don't think there is any need to allow class in an expression, since
>>> we already have type().
>>
>> But type doesn't allow you to do most of what you can do in a class definition. This is like arguing that we don't need expression def because we already have types.FunctionType.
>
> Given multi-line lambda, what could you do in a class definition that
> you couldn't do with type?
Write code that's somewhat readable and looks somewhat like Python?
> class Spam(SpamBase, HamBase):
> x = 1
> def eggs(self, arg):
> return arg+self.x
>
> classes = [int, str, Spam, float]
>
>
> would become:
>
>
> classes = [int, str,
> type('Spam', (SpamBase, HamBase),
> {'x': 1,
> 'eggs': (def eggs(self, arg):
> return arg+self.x
> ),
> }
> ),
> float,
> ]
>
>
> which I personally don't consider an improvement, but some people might.
Anyone who finds that an improvement clearly would rather be using a different language than python in the first place.
> You could even handle metaclasses and extra arguments:
>
> class Spam(SpamBase, metaclass=MetaSpam, extrakw="extra"):
> ...
>
> becomes:
>
> MetaSpam('Spam', (SpamBase,), {...}, extrakw="extra")
>
> so given a def expression, I don't think we also need a class
> expression. What's missing?
>
>
>
> --
> Steven
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
More information about the Python-ideas
mailing list