Instagram / Instagram/Fixit

NoRedundantLambda's autofix is not always safe

Open
#509 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
714
Forks
72
PR merge metrics
No merged PRs in 30d

Description

The documentation states that:

> A lamba function which has a single objective of passing all it is arguments to another callable can be safely replaced by that callable.

But this is not always true. For instance:

```python
get_now_isoformat = lambda: datetime.now().isoformat()
```

This will be autofixed this way:

```python
get_now_isoformat = datetime.now().isoformat
```

But the two functions do not have the same behaviour:

```python
>>> # A different result is returned everytime the function is called
>>> get_now_isoformat_v1() == get_now_isoformat_v1()
False
>>> # The result is "frozen"
>>> get_now_isoformat_v2() == get_now_isoformat_v2()
True
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.