Skip to content

NoRedundantLambda's autofix is not always safe #509

@julienc91

Description

@julienc91

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:

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

This will be autofixed this way:

get_now_isoformat = datetime.now().isoformat

But the two functions do not have the same behaviour:

>>> # 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions