Repository navigation
[pyflakes] Mark the fix as unsafe when it creates a docstring (F541) - #28258
Conversation
The fix is now unsafe in docstring positions. The reason is that removing the `f` turns the f-string into a string literal, and this changes what the program exposes as documentation. It does not touch the checker or any other rule. The scope is wider than what was reported in the issue. Listing the positions to make the scope clear: - the first statement of a module body - the first statement of a class body - the first statement of a function body - after a simple assignment (`a = 1`) at module level or in a class body - after an annotated assignment (`b: int = 2`), likewise
|
…d ISC003 Mainly the method `Checker::in_docstring_position(range)` in `checkers/ast/mod.rs`, covering the five positions. It's also worth knowing that F541 and ISC003 both use it, so their two helpers go away. ISC003 inherits attribute docstrings. Migration of the F541 tests from `.py` fixture + snapshots to mdtest, with a new case (previous statement that is not an assignment). 2828 tests, 38 mdtests, clippy clean.
|
Changes from the first push: The helper was extracted to
I applied the suggestions @ntBre asked for ( Most importantly: ISC003 inherited attribute docstrings. Its fixture had an I also think it's worth mentioning that Tests came out at 2828, 38 mdtests, clippy clean. |
|
We support using AI (i.e., LLMs) while coding. However, AI should not be used to communicate with maintainers. Please read and follow our AI policy when submitting issues and pull requests. |
|
I’ll write shorter and more direct from now on. |
|
Hi @ntBre, the changes from the last review are done and the branch is up to date too! |
ntBre
left a comment
There was a problem hiding this comment.
Thanks! Codex noticed a small issue with weird code like:
class C:
if condition:
x = 1
f"Attribute documentation"So I pushed a commit addressing it. This otherwise looked good to me.
Thanks for the review. Im very focused on improving my code for this project! |
Summary
The fix is now unsafe in docstring positions. The reason is that removing the
fturns the f-string into a string literal, and this changes what the program exposes as documentation.It does not touch the checker or any other rule. The scope is wider than what was reported in the issue. Listing the positions to make the scope clear:
a = 1) at module level or in a class bodyb: int = 2), likewiseI say documentation and not runtime because attribute docstrings don't touch
__doc__.c = d = 3stays safe because this mirrors the checker's own criterion.Fixes #18807
Test Plan
2828 passed, 0 failed. Tested with:
--fixwithout the flag on the unsafe case and the file didn't change; with--unsafe-fixesit did. The safe case was fixed without the flagF541.pysnapshot didn't movecargo clippy --workspace --all-targets --all-features -- -D warningscleanprek run --all-files: 14 hooks