Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix B008 edge case with lambda functions #243

Merged
merged 1 commit into from
Mar 25, 2022

Conversation

jpy-git
Copy link
Contributor

@jpy-git jpy-git commented Mar 25, 2022

Closes #242

In #239 I introduced the ability to detect functions at any depth of function default args to prevent things like:

def foo(a=[datetime.now()], b=bar(datetime.now())): ...

One thing I overlooked was lambda functions which are slightly different given that their contents act as function body and are therefore only evaluated when the lambda function is called, therefore B008 doesn't apply to these.

from datetime import datetime
import time

def foo(f=lambda x: datetime.now()):
    print(f(1))
    time.sleep(5)
    print(f(1))

foo()

prints

2022-03-25 11:36:22.999143
2022-03-25 11:36:28.004194

Fix is pretty simple, don't check inside lambda functions.

@cooperlees
Copy link
Collaborator

Wonder why CI didn't run here? That is very strange ...

@jpy-git jpy-git closed this Mar 25, 2022
@jpy-git jpy-git reopened this Mar 25, 2022
@jpy-git
Copy link
Contributor Author

jpy-git commented Mar 25, 2022

@cooperlees Strange, I've found that closing and reopening a PR seems to fix these things 😅

@cooperlees
Copy link
Collaborator

And it did. Wonder where we can log the bug?

Copy link
Collaborator

@cooperlees cooperlees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me. Thanks!

@cooperlees cooperlees merged commit 40a9381 into PyCQA:main Mar 25, 2022
@jpy-git jpy-git deleted the b008_lambda_edge_case branch March 25, 2022 16:55
@jpy-git
Copy link
Contributor Author

jpy-git commented Mar 25, 2022

And it did. Wonder where we can log the bug?

Maybe a GitHub bug report: https://support.github.com/contact/bug-report

Although tbh I've only ever had it happen once before and closing/reopening or pushing another commit seems to re-trigger things so not too big an issue 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

function calls inside lambda is warned as B008
2 participants