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

B023 is real #6304

Merged
merged 2 commits into from Aug 31, 2022
Merged

B023 is real #6304

merged 2 commits into from Aug 31, 2022

Conversation

dimbleby
Copy link
Contributor

Here's some sample code approximating the poetry code:

#!/usr/bin/env python3


def one() -> int:
    return 1


def two() -> int:
    return 2


def three() -> int:
    return 3


factories = [one, two, three]

registered = []
for factory in factories:
    registered.append(lambda: factory())

for registered_factory in registered:
    print(f"result is {registered_factory()}")

output is

result is 3
result is 3
result is 3

which is exactly the gotcha that flake8-bugbear's B023 was trying to warn about.

I've applied one of the workarounds that various parts of the internet recommend, and you can verify for yourself if you're so inclined that doing the same in the toy script gives the expected output.

@dimbleby
Copy link
Contributor Author

Although come to think of it this particular case could surely be more compactly fixed by not lambda-ing at all, register_factory(command.name, command) should do the job

@dimbleby
Copy link
Contributor Author

I've pushed the more compact fix in a second commit so that this discussion, such as it is, still makes sense. Feel free to squash if and when merging.

neersighted
neersighted previously approved these changes Aug 31, 2022
@neersighted neersighted merged commit 113f9fa into python-poetry:master Aug 31, 2022
@dimbleby dimbleby deleted the b023-is-real branch August 31, 2022 19:13
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants