This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ahopkins
Recipients ahopkins
Date 2022-02-27.13:15:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1645967729.03.0.78553115173.issue46873@roundup.psfhosted.org>
In-reply-to
Content
I believe the following produces an unexpected behavior:

    from inspect import getsource


    def bar(*funcs):
        def decorator(func):
            return func

        return decorator


    @bar(lambda x: bool(True), lambda x: False)
    async def foo():
        ...


    print(getsource(foo))

The output shows only the decorator declaration and none of the function:

    @bar(lambda x: bool(True), lambda x: False)


From my investigation, it seems like this requires the following conditions to be true:
- lambdas are passed in decorator arguments
- there is more than one lambda
- at least one of the lambdas has a function call

Passing the lambdas as default function arguments seems okay:

    async def foo(bar=[lambda x: bool(True), lambda x: False]):
        ...

A single lambda seems okay:

    @bar(lambda x: bool(True))
    async def foo():
        ...

Lambdas with no function calls also seem okay:

    @bar(lambda x: not x, lambda: True)
    async def foo():
        ...

Tested this on:
- Python 3.10.2
- Python 3.9.9
- Python 3.8.11
- Python 3.7.12
History
Date User Action Args
2022-02-27 13:15:29ahopkinssetrecipients: + ahopkins
2022-02-27 13:15:29ahopkinssetmessageid: <1645967729.03.0.78553115173.issue46873@roundup.psfhosted.org>
2022-02-27 13:15:29ahopkinslinkissue46873 messages
2022-02-27 13:15:28ahopkinscreate