Message414149
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 |
|
Date |
User |
Action |
Args |
2022-02-27 13:15:29 | ahopkins | set | recipients:
+ ahopkins |
2022-02-27 13:15:29 | ahopkins | set | messageid: <1645967729.03.0.78553115173.issue46873@roundup.psfhosted.org> |
2022-02-27 13:15:29 | ahopkins | link | issue46873 messages |
2022-02-27 13:15:28 | ahopkins | create | |
|