-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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-pyi
] Implement PYI064
#11325
Conversation
w1: Final[Literal[123]] # PYI064 | ||
|
||
# This should be fixable, but marked as unsafe | ||
w2: Final[Literal[123]] = "random value" # PYI064 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think an unsafe autofix is appropriate here (specifically when the assignment value is different from the literal value).
Is autofixing it to w2: Final = 123
in unsafe mode fair?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ummmmmmm this kind of thing doesn't really make any sense, right? I think I'd lean towards not doing an autofix here -- "refuse the temptation to guess"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
|
|
||
// Discards tuples like `Literal[1, 2, 3]` | ||
// and complex literals like `Literal[{1, 2}]` | ||
if !matches!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can potentially be moved to ruff_python_ast/src/helpers.rs
, as a is_literal_expr
helper.
PlatformName = Literal["linux", "macos", "windows"] | ||
PLATFORMS: Final[set[PlatformName]] = {"linux", "macos", "windows"} # No issue here | ||
|
||
foo: Final[{1, 2, 3}] = {1, 2, 3} # No issue here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now this mimics flake8-pyi
behaviour, however I think raising the issue here should be fine?
@AlexWaygood -- will follow-up and merge this. |
flake8-pyi
] Implement PYI064
Summary
Implements
Y064
fromflake8-pyi
and its autofix.Test Plan
cargo test
/cargo insta review