Skip to content

Commit 141bfa8

Browse files
committed
Extend unnecessary-type-conversion lint to redundant bytes() calls.
1 parent 96913d0 commit 141bfa8

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

crates/pyrefly_config/src/error_kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ pub enum ErrorKind {
276276
/// Identity comparison (`is` or `is not`) between types that are provably disjoint
277277
/// or between literals whose comparison result is statically known.
278278
UnnecessaryComparison,
279-
/// Warning when calling a builtin type constructor (str, int, float, bool) on a value that is already of that type.
279+
/// Warning when calling a builtin type constructor (str, int, float, bytes) on a value that is already of that type.
280280
UnnecessaryTypeConversion,
281281
/// A return or yield that can never be reached.
282282
/// This occurs when a return/yield follows a statement that always exits,

pyrefly/lib/alt/call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
10071007
range: TextRange,
10081008
errors: &ErrorCollector,
10091009
) {
1010-
let builtin_names = ["str", "int", "float"];
1010+
let builtin_names = ["str", "int", "float", "bytes"];
10111011
if !builtin_names
10121012
.iter()
10131013
.any(|name| cls.has_qname("builtins", name))

pyrefly/lib/test/unnecessary_type_conversion.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ def f(x: Any) -> None:
5656
"#,
5757
);
5858

59+
testcase!(
60+
test_bytes_to_bytes,
61+
r#"
62+
def f(x: bytes) -> None:
63+
y = bytes(x) # E: Unnecessary `bytes()` call; argument is already of type `bytes`
64+
"#,
65+
);
66+
5967
testcase!(
6068
test_no_args_ok,
6169
r#"

0 commit comments

Comments
 (0)