Skip to content

Commit

Permalink
Add tests for pylint-dev#8192
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdrozd committed Sep 28, 2024
1 parent 1288111 commit 5f57434
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 21 additions & 1 deletion tests/functional/u/unnecessary/unnecessary_lambda.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pylint: disable=undefined-variable, use-list-literal, unnecessary-lambda-assignment, use-dict-literal
# pylint: disable=undefined-variable, use-list-literal, unnecessary-lambda-assignment, use-dict-literal, disallowed-name
"""test suspicious lambda expressions
"""

Expand Down Expand Up @@ -65,3 +65,23 @@ def f(d):
_ = lambda x: x(x)
_ = lambda x, y: x(x, y)
_ = lambda x: z(lambda y: x + y)(x)


# https://github.com/pylint-dev/pylint/issues/8192

# foo does not yet exist, so replacing lambda x: foo.get(x) with
# foo.get will raise NameError
g = lambda x: foo.get(x) # [unnecessary-lambda] FALSE POSITIVE

# an object is created and given the name 'foo'
foo = {1: 2}
assert g(1) == 2

# a new object is created and given the name 'foo'; first object is lost
foo = {1: 3}
assert g(1) == 3

# the name 'foo' is deleted; second object is lost; there is no foo
del foo

assert g(1) == 3 # NameError: name 'foo' is not defined
1 change: 1 addition & 0 deletions tests/functional/u/unnecessary/unnecessary_lambda.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ unnecessary-lambda:23:4:23:53:<lambda>:Lambda may not be necessary:UNDEFINED
unnecessary-lambda:25:4:25:71:<lambda>:Lambda may not be necessary:UNDEFINED
unnecessary-lambda:29:4:29:31:<lambda>:Lambda may not be necessary:UNDEFINED
unnecessary-lambda:31:4:31:44:<lambda>:Lambda may not be necessary:UNDEFINED
unnecessary-lambda:74:4:74:24:<lambda>:Lambda may not be necessary:UNDEFINED

0 comments on commit 5f57434

Please sign in to comment.