Skip to content

Commit 7587286

Browse files
author
Matthieu Ancellin
committed
Fix example cases.
1 parent 3372df6 commit 7587286

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

labelled_functions/decorators.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# coding: utf-8
33
"""Some higher-order functions that make useful tools."""
44

5+
from labelled_functions.abstract import Unknown
56
from labelled_functions.labels import label, LabelledFunction
67

78

@@ -19,12 +20,13 @@ def func_returning_inputs(*args, **kwargs):
1920
func_returning_inputs,
2021
name=f"{func.name}",
2122
input_names=func.input_names,
22-
output_names=func.input_names + func.output_names,
23+
output_names=func.input_names + func.output_names if func.output_names is not Unknown else Unknown,
2324
default_values=func.default_values,
2425
)
2526

2627
return func_returning_inputs
2728

29+
2830
def time(func):
2931
func = label(func)
3032

labelled_functions/labels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import parso
1111

12-
from .abstract import Unknown, AbstractLabelledCallable
12+
from labelled_functions.abstract import Unknown, AbstractLabelledCallable
1313

1414

1515
# API
@@ -106,7 +106,7 @@ def __init__(self,
106106
if p[name].default is not Parameter.empty}
107107

108108
# OUTPUT
109-
if output_names is Unknown:
109+
if output_names is Unknown and function.__name__ != "<lambda>":
110110
try:
111111
source = getsource(function)
112112
output_names = _get_output_names_from_source(source)

test/test_labels.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55
from copy import copy
66

7+
from labelled_functions.abstract import Unknown
78
from labelled_functions.labels import LabelledFunction, label
89
from labelled_functions.decorators import keeping_inputs
910

@@ -54,6 +55,11 @@ def f(self, x):
5455
assert lab_f(A(), x=2) == 14
5556

5657

58+
def test_lambda():
59+
ld = label(lambda foo: 2*foo)
60+
assert ld.input_names == ["foo"]
61+
assert ld.output_names is Unknown
62+
5763
def test_output_checking():
5864
la = LabelledFunction(add, output_names=['shrubbery'])
5965
assert la._has_never_been_run

0 commit comments

Comments
 (0)