Skip to content

Commit 485dfe0

Browse files
Евгений БлиновЕвгений Блинов
authored andcommitted
Refactor is_lambda into helper module with tests
1 parent 69eb3b3 commit 485dfe0

5 files changed

Lines changed: 22 additions & 5 deletions

File tree

getsources/hash.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import hashlib
22
from typing import Any, Callable
33
from ast import parse, Expr, Constant, Lambda, get_source_segment, walk
4-
from types import FunctionType
54

65
from getsources import getclearsource
6+
from getsources.helpers.is_lambda import is_lambda
77

88
ALPHABET = '0123456789ABCDEFGHJKMNPQRSTVWXYZ'
99

1010

11-
def is_lambda(function: Callable[..., Any]):
12-
return isinstance(function, FunctionType) and function.__name__ == "<lambda>"
13-
14-
1511
def get_body_text(function: Callable[..., Any], source: str, skip_docstring: bool) -> str:
1612
tree = parse(source)
1713

getsources/helpers/__init__.py

Whitespace-only changes.

getsources/helpers/is_lambda.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from types import FunctionType
2+
from typing import Any, Callable
3+
4+
5+
def is_lambda(function: Callable[..., Any]):
6+
return isinstance(function, FunctionType) and function.__name__ == "<lambda>"

tests/helpers/__init__.py

Whitespace-only changes.

tests/helpers/test_is_lambda.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from getsources.helpers.is_lambda import is_lambda
2+
3+
4+
def test_lambdas_are_lambdas():
5+
assert is_lambda(lambda x: x)
6+
assert is_lambda(lambda x: None)
7+
assert is_lambda(lambda: None)
8+
9+
10+
def test_are_not_lambdas(transformed):
11+
@transformed
12+
def function():
13+
...
14+
15+
assert not is_lambda(function)

0 commit comments

Comments
 (0)