Skip to content

Commit eff84ca

Browse files
committed
Async pipe decorator: preserve wrapped func signature
1 parent debd0d2 commit eff84ca

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

cylc/flow/async_util.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import asyncio
1919
from functools import partial, wraps
20+
from inspect import signature
2021
import os
2122
from pathlib import Path
2223
from typing import List, Union
@@ -262,10 +263,22 @@ def __str__(self):
262263
def __repr__(self):
263264
return _AsyncPipe(self.func).__repr__()
264265

266+
@property
267+
def __name__(self):
268+
return self.func.__name__
269+
265270
@property
266271
def __doc__(self):
267272
return self.func.__doc__
268273

274+
@property
275+
def __signature__(self):
276+
return signature(self.func)
277+
278+
@property
279+
def __annotations__(self):
280+
return self.func.__annotations__
281+
269282

270283
def pipe(func=None, preproc=None):
271284
"""An asynchronous pipe implementation in pure Python.

tests/unit/test_async_util.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
import asyncio
18+
from inspect import signature
1819
import logging
1920
from pathlib import Path
2021
from random import random
@@ -209,14 +210,17 @@ def test_pipe_brackets():
209210

210211

211212
@pipe
212-
async def documented(x):
213+
async def documented(x: str, y: int = 0):
213214
"""The docstring for the pipe function."""
214215
pass
215216

216217

217218
def test_documentation():
218-
"""It should preserve the docstring of pipe functions."""
219+
"""It should preserve the docstring, signature & annotations of
220+
the wrapped function."""
219221
assert documented.__doc__ == 'The docstring for the pipe function.'
222+
assert documented.__annotations__ == {'x': str, 'y': int}
223+
assert str(signature(documented)) == '(x: str, y: int = 0)'
220224

221225

222226
def test_rewind():

0 commit comments

Comments
 (0)