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

Pyupgrade: Printf string formatting #1803

Merged
merged 77 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
bf7e246
Got some basic stuff in
colin99d Jan 11, 2023
bdb3b43
Merge branch 'main' into PrintfStringFormatting
colin99d Jan 11, 2023
84717ea
GOt ONE unit test passing, LETS GO
colin99d Jan 12, 2023
7efb4ec
Better handle empty strings
colin99d Jan 12, 2023
d4fabbb
Fix how i handle string_end
colin99d Jan 12, 2023
a32ce74
Fixed another bug
colin99d Jan 12, 2023
37069f7
Finished unit tests
colin99d Jan 12, 2023
a4bd9a0
Merge branch 'main' into PrintfStringFormatting
colin99d Jan 12, 2023
c240f43
About to actually get this thing linting
colin99d Jan 13, 2023
99ce56e
Finished the body of the printf_string_formatting function
colin99d Jan 13, 2023
5e6939d
Fixed the regex
colin99d Jan 13, 2023
58a1d7d
Finished unit tests (2 failing, and also simplified them BIG time)
colin99d Jan 13, 2023
0756ffa
Minor wording change
colin99d Jan 13, 2023
dadb075
Fixed one bug
colin99d Jan 13, 2023
25be7ae
Fixed last issue with unit tests
colin99d Jan 13, 2023
d1c9d26
Cleaned prints
colin99d Jan 13, 2023
d863ce5
Going through errors
colin99d Jan 13, 2023
bfa6ad2
better handling
colin99d Jan 14, 2023
3265eb7
Added integration tests
colin99d Jan 14, 2023
edcbb5d
Fixed one issue
colin99d Jan 14, 2023
757c71d
Fixed the nested issue
colin99d Jan 14, 2023
92d5503
Increase comments
colin99d Jan 14, 2023
abb9276
Merged with new main
colin99d Jan 14, 2023
daf5da8
Two edge cases left on tuple
colin99d Jan 14, 2023
0fa0d8c
Refactored check_statement outside of main function
colin99d Jan 14, 2023
bb9c4c4
Better handling
colin99d Jan 14, 2023
dd88455
Git rid of nesting, cleaner code now
colin99d Jan 14, 2023
e520d83
Fixed one of two tuple errors, just need to fix regex one now
colin99d Jan 14, 2023
3212e67
In progress, but need to switch
colin99d Jan 15, 2023
ca40881
Moving towards a complete dict implementation
colin99d Jan 15, 2023
b36d8c3
Final testing for dict
colin99d Jan 15, 2023
c7c626d
Updated test cases
colin99d Jan 15, 2023
9e5ac12
Ran new tests
colin99d Jan 15, 2023
c952500
Fixed formatting, removed prints
colin99d Jan 15, 2023
e738b4a
linted clippy and added docs
colin99d Jan 15, 2023
e1647cd
Fixed typos and fmt
colin99d Jan 15, 2023
9d41062
Added correct level of visibility
colin99d Jan 15, 2023
3f5148f
Replaced string with Option<String> to increase readability
colin99d Jan 15, 2023
5f89844
Merge branch 'main' into PrintfStringFormatting
charliermarsh Jan 17, 2023
07688c0
Minor tweaks
charliermarsh Jan 17, 2023
8526f11
Fix reference
charliermarsh Jan 17, 2023
3e9f728
Simplified to a broken curly_escape
colin99d Jan 17, 2023
420f934
Fixed dict tests
colin99d Jan 17, 2023
0793afd
Fixed embarassing mistake in docstring
colin99d Jan 17, 2023
e7390be
Added unit tests for the issues Charlie found
colin99d Jan 17, 2023
0bee8af
Merge branch 'main' into PrintfStringFormatting
charliermarsh Jan 17, 2023
b042fd8
Merged
colin99d Jan 18, 2023
e571735
Merged
colin99d Jan 18, 2023
de90d4d
Fixed glitch from merge
colin99d Jan 18, 2023
ebee722
Began conversion to cformatstring
colin99d Jan 18, 2023
32aec6b
Progressed
colin99d Jan 18, 2023
6056ebc
Merge branch 'main' into PrintfStringFormatting
colin99d Jan 18, 2023
92872b6
Got a little further
colin99d Jan 19, 2023
7d8d14c
Merge branch 'main' into PrintfStringFormatting
charliermarsh Jan 19, 2023
923b43d
Merge remote-tracking branch 'refs/remotes/origin/main' into PrintfSt…
charliermarsh Jan 20, 2023
b06be38
Fixed two tests
colin99d Jan 20, 2023
acfdb51
Merged
colin99d Jan 20, 2023
675f6fc
working towards a better solution
colin99d Jan 20, 2023
e8702e5
Fixed tests
colin99d Jan 20, 2023
522eb70
Merge branch 'main' into PrintfStringFormatting
charliermarsh Jan 20, 2023
6d89c87
Upgrade RustPython parser
charliermarsh Jan 20, 2023
837b487
Fix Clippy
charliermarsh Jan 20, 2023
8f54ebd
Mid refactor
charliermarsh Jan 20, 2023
d805dc7
Merge branch 'main' into PrintfStringFormatting
charliermarsh Jan 20, 2023
e8e6912
Misc changes
charliermarsh Jan 20, 2023
4660713
Mid-way through conversion
charliermarsh Jan 20, 2023
1c7179d
Merge branch 'main' into PrintfStringFormatting
charliermarsh Jan 20, 2023
dac86ab
Merge branch 'main' into PrintfStringFormatting
charliermarsh Jan 20, 2023
76ddc62
Try to move tests
charliermarsh Jan 21, 2023
012144b
Add prints
charliermarsh Jan 21, 2023
3cfc93a
Add some restrictions
charliermarsh Jan 21, 2023
60e73d5
Try out a lexer
charliermarsh Jan 21, 2023
31ae316
Support emoji
charliermarsh Jan 21, 2023
39fd5bc
Merge branch 'main' into PrintfStringFormatting
charliermarsh Jan 21, 2023
a5e5c1d
Fix ) case
charliermarsh Jan 21, 2023
b179026
Merge branch 'main' into PrintfStringFormatting
charliermarsh Jan 21, 2023
85d75e8
Point to latest RustPython
charliermarsh Jan 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Got some basic stuff in
  • Loading branch information
colin99d committed Jan 11, 2023
commit bf7e246b59e484f7d78f5f0cb520386617a27a91
3 changes: 3 additions & 0 deletions resources/test/fixtures/pyupgrade/UP031.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'%s %s' % (a, b)

# Make sure to include assignment and inside a call, also multi-line
3 changes: 3 additions & 0 deletions src/checkers/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2589,6 +2589,9 @@ where
}
}
}
if self.settings.enabled.contains(&RuleCode::UP031) {
pyupgrade::rules::printf_string_formatting(self, left, right);
}
}
}
ExprKind::BinOp {
Expand Down
2 changes: 2 additions & 0 deletions src/pyupgrade/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub(crate) use use_pep585_annotation::use_pep585_annotation;
pub(crate) use use_pep604_annotation::use_pep604_annotation;
pub(crate) use useless_metaclass_type::useless_metaclass_type;
pub(crate) use useless_object_inheritance::useless_object_inheritance;
pub(crate) use printf_string_formatting::printf_string_formatting;

use crate::ast::helpers::{self};
use crate::ast::types::{Range, Scope, ScopeKind};
Expand Down Expand Up @@ -65,6 +66,7 @@ mod use_pep585_annotation;
mod use_pep604_annotation;
mod useless_metaclass_type;
mod useless_object_inheritance;
mod printf_string_formatting;

/// UP008
pub fn super_args(
Expand Down
9 changes: 9 additions & 0 deletions src/pyupgrade/rules/printf_string_formatting.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use crate::checkers::ast::Checker;
use rustpython_ast::Expr;

/// UP031
pub fn printf_string_formatting(checker: &mut Checker, left: &Expr, right: &Expr) {
println!("{:?}", left);
println!("==========");
println!("{:?}", right);
}
1 change: 1 addition & 0 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ define_rule_mapping!(
UP028 => violations::RewriteYieldFrom,
UP029 => violations::UnnecessaryBuiltinImport,
UP030 => violations::FormatLiterals,
UP031 => violations::PrintfStringFormatting,
// pydocstyle
D100 => violations::PublicModule,
D101 => violations::PublicClass,
Expand Down
19 changes: 19 additions & 0 deletions src/violations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3486,6 +3486,25 @@ impl AlwaysAutofixableViolation for ReplaceUniversalNewlines {
}
}

define_violation!(
pub struct PrintfStringFormatting;
);
impl AlwaysAutofixableViolation for PrintfStringFormatting {
fn message(&self) -> String {
"Use builtin `open`".to_string()
}

fn autofix_title(&self) -> String {
"Replace with builtin `open`".to_string()
}

fn placeholder() -> Self {
// FOR REVIEWER: Should we switch all of these to self? Is there any way to do this automatically when
// defining the trait (im pretty sure the answer is no, but I want to confirm)
Self
}
}

define_violation!(
pub struct ReplaceStdoutStderr;
);
Expand Down