-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Format bytes string #6166
Format bytes string #6166
Conversation
PR Check ResultsBenchmarkLinux
Windows
|
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.
Nice! Thank you
@@ -51,16 +51,13 @@ impl FormatNodeRule<ExprConstant> for FormatExprConstant { | |||
Constant::Int(_) => FormatInt::new(item).fmt(f), | |||
Constant::Float(_) => FormatFloat::new(item).fmt(f), | |||
Constant::Complex { .. } => FormatComplex::new(item).fmt(f), | |||
Constant::Str(_) => { | |||
Constant::Str(_) | Constant::Bytes(_) => { | |||
let string_layout = match self.layout { | |||
ExprConstantLayout::Default => StringLayout::Default, | |||
ExprConstantLayout::String(layout) => layout, | |||
}; | |||
FormatString::new(item).with_layout(string_layout).fmt(f) |
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.
@konstin I'm a bit surprised that black also normalizes byte strings because I assumed we would need to treat them as opaque bytes. Are you aware of any normalization that isn't safe for byte strings?
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.
as far as i know and reading https://docs.python.org/3/library/stdtypes.html#bytes, byte strings are pretty much like normal strings except that they are limited to ascii input, allow arbitrary bytes and \x
behaves differently
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.
Thanks!
Summary
Format bytes string
Closes #6064
Test Plan
Added a fixture based on string's one