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

[flake8-bugbear] Fix mutable-contextvar-default (B039) to resolve annotated function calls properly #14532

Merged
merged 5 commits into from
Nov 24, 2024

Conversation

harupy
Copy link
Contributor

@harupy harupy commented Nov 22, 2024

Summary

Fix #14525

Test Plan

New test cases

@harupy harupy changed the title [flake8-bugbear] Fix mutable-contextvar-default (B039) to handle annotated calls [flake8-bugbear] Fix mutable-contextvar-default (B039) to handle annotated calls properly Nov 22, 2024
@harupy harupy changed the title [flake8-bugbear] Fix mutable-contextvar-default (B039) to handle annotated calls properly [flake8-bugbear] Fix mutable-contextvar-default (B039) to flag annotated function calls Nov 22, 2024
Copy link
Contributor

github-actions bot commented Nov 22, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@harupy harupy changed the title [flake8-bugbear] Fix mutable-contextvar-default (B039) to flag annotated function calls [flake8-bugbear] Fix mutable-contextvar-default (B039) to resolve annotated function calls properly Nov 22, 2024
@MichaReiser MichaReiser added the bug Something isn't working label Nov 22, 2024
@@ -96,7 +97,7 @@ pub(crate) fn mutable_contextvar_default(checker: &mut Checker, call: &ast::Expr
&& !is_immutable_func(func, checker.semantic(), &extend_immutable_calls)))
&& checker
.semantic()
.resolve_qualified_name(&call.func)
.resolve_qualified_name(map_subscript(&call.func))
Copy link
Contributor Author

@harupy harupy Nov 23, 2024

Choose a reason for hiding this comment

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

Unrelated to this PR, but shoud we check if call.func is contextvars.Contextvar first (and exit if not) before checking if arguments has a keyword default to avoid unnecessary work (immutability check and extending the immutable expressions)?

@charliermarsh charliermarsh merged commit e3d7926 into astral-sh:main Nov 24, 2024
20 checks passed
@charliermarsh
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

B039 considers frozenset to be mutable
3 participants