---
source: crates/ruff_linter/src/rules/pyupgrade/mod.rs
---
UP018 [*] Unnecessary `str` call (rewrite as a literal)
  --> UP018.py:8:1
   |
 6 |   str("foo", **k)
 7 |   str("foo", encoding="UTF-8")
 8 | / str("foo"
 9 | |     "bar")
   | |__________^
10 |   str(b"foo")
11 |   bytes("foo", encoding="UTF-8")
   |
help: Replace with string literal
  |
7 | str("foo", encoding="UTF-8")
  - str("foo"
8 + ("foo"
9 |     "bar")
  |

UP018 [*] Unnecessary `bytes` call (rewrite as a literal)
  --> UP018.py:15:1
   |
13 |   bytes("foo", *a)
14 |   bytes("foo", **a)
15 | / bytes(b"foo"
16 | |       b"bar")
   | |_____________^
17 |   bytes("foo")
18 |   bytes(1)
   |
help: Replace with bytes literal
   |
14 | bytes("foo", **a)
   - bytes(b"foo"
15 + (b"foo"
16 |       b"bar")
   |

UP018 [*] Unnecessary `int` call (rewrite as a literal)
  --> UP018.py:34:1
   |
32 | bool(b"")
33 | bool(1.0)
34 | int().denominator
   | ^^^^^
35 |
36 | # These become literals
   |
help: Replace with integer literal
   |
33 | bool(1.0)
   - int().denominator
34 + (0).denominator
35 |
   |

UP018 [*] Unnecessary `str` call (rewrite as a literal)
  --> UP018.py:37:1
   |
36 | # These become literals
37 | str()
   | ^^^^^
38 | str("foo")
39 | str("""
   |
help: Replace with string literal
   |
36 | # These become literals
   - str()
37 + ""
38 | str("foo")
   |

UP018 [*] Unnecessary `str` call (rewrite as a literal)
  --> UP018.py:38:1
   |
36 | # These become literals
37 | str()
38 | str("foo")
   | ^^^^^^^^^^
39 | str("""
40 | foo""")
   |
help: Replace with string literal
   |
37 | str()
   - str("foo")
38 + "foo"
39 | str("""
   |

UP018 [*] Unnecessary `str` call (rewrite as a literal)
  --> UP018.py:39:1
   |
37 |   str()
38 |   str("foo")
39 | / str("""
40 | | foo""")
   | |_______^
41 |   bytes()
42 |   bytes(b"foo")
   |
help: Replace with string literal
   |
38 | str("foo")
   - str("""
   - foo""")
39 + """
40 + foo"""
41 | bytes()
   |

UP018 [*] Unnecessary `bytes` call (rewrite as a literal)
  --> UP018.py:41:1
   |
39 | str("""
40 | foo""")
41 | bytes()
   | ^^^^^^^
42 | bytes(b"foo")
43 | bytes(b"""
   |
help: Replace with bytes literal
   |
40 | foo""")
   - bytes()
41 + b""
42 | bytes(b"foo")
   |

UP018 [*] Unnecessary `bytes` call (rewrite as a literal)
  --> UP018.py:42:1
   |
40 | foo""")
41 | bytes()
42 | bytes(b"foo")
   | ^^^^^^^^^^^^^
43 | bytes(b"""
44 | foo""")
   |
help: Replace with bytes literal
   |
41 | bytes()
   - bytes(b"foo")
42 + b"foo"
43 | bytes(b"""
   |

UP018 [*] Unnecessary `bytes` call (rewrite as a literal)
  --> UP018.py:43:1
   |
41 |   bytes()
42 |   bytes(b"foo")
43 | / bytes(b"""
44 | | foo""")
   | |_______^
45 |   f"{str()}"
46 |   int()
   |
help: Replace with bytes literal
   |
42 | bytes(b"foo")
   - bytes(b"""
   - foo""")
43 + b"""
44 + foo"""
45 | f"{str()}"
   |

UP018 [*] Unnecessary `str` call (rewrite as a literal)
  --> UP018.py:45:4
   |
43 | bytes(b"""
44 | foo""")
45 | f"{str()}"
   |    ^^^^^
46 | int()
47 | int(1)
   |
help: Replace with string literal
   |
44 | foo""")
   - f"{str()}"
45 + f"{''}"
46 | int()
   |

UP018 [*] Unnecessary `int` call (rewrite as a literal)
  --> UP018.py:46:1
   |
44 | foo""")
45 | f"{str()}"
46 | int()
   | ^^^^^
47 | int(1)
48 | float()
   |
help: Replace with integer literal
   |
45 | f"{str()}"
   - int()
46 + 0
47 | int(1)
   |

UP018 [*] Unnecessary `int` call (rewrite as a literal)
  --> UP018.py:47:1
   |
45 | f"{str()}"
46 | int()
47 | int(1)
   | ^^^^^^
48 | float()
49 | float(1.0)
   |
help: Replace with integer literal
   |
46 | int()
   - int(1)
47 + 1
48 | float()
   |

UP018 [*] Unnecessary `float` call (rewrite as a literal)
  --> UP018.py:48:1
   |
46 | int()
47 | int(1)
48 | float()
   | ^^^^^^^
49 | float(1.0)
50 | bool()
   |
help: Replace with float literal
   |
47 | int(1)
   - float()
48 + 0.0
49 | float(1.0)
   |

UP018 [*] Unnecessary `float` call (rewrite as a literal)
  --> UP018.py:49:1
   |
47 | int(1)
48 | float()
49 | float(1.0)
   | ^^^^^^^^^^
50 | bool()
51 | bool(True)
   |
help: Replace with float literal
   |
48 | float()
   - float(1.0)
49 + 1.0
50 | bool()
   |

UP018 [*] Unnecessary `bool` call (rewrite as a literal)
  --> UP018.py:50:1
   |
48 | float()
49 | float(1.0)
50 | bool()
   | ^^^^^^
51 | bool(True)
52 | bool(False)
   |
help: Replace with boolean literal
   |
49 | float(1.0)
   - bool()
50 + False
51 | bool(True)
   |

UP018 [*] Unnecessary `bool` call (rewrite as a literal)
  --> UP018.py:51:1
   |
49 | float(1.0)
50 | bool()
51 | bool(True)
   | ^^^^^^^^^^
52 | bool(False)
   |
help: Replace with boolean literal
   |
50 | bool()
   - bool(True)
51 + True
52 | bool(False)
   |

UP018 [*] Unnecessary `bool` call (rewrite as a literal)
  --> UP018.py:52:1
   |
50 | bool()
51 | bool(True)
52 | bool(False)
   | ^^^^^^^^^^^
53 |
54 | # These become a literal but retain parentheses
   |
help: Replace with boolean literal
   |
51 | bool(True)
   - bool(False)
52 + False
53 |
   |

UP018 [*] Unnecessary `int` call (rewrite as a literal)
  --> UP018.py:55:1
   |
54 | # These become a literal but retain parentheses
55 | int(1).denominator
   | ^^^^^^
56 |
57 | # These too are literals in spirit
   |
help: Replace with integer literal
   |
54 | # These become a literal but retain parentheses
   - int(1).denominator
55 + (1).denominator
56 |
   |

UP018 [*] Unnecessary `int` call (rewrite as a literal)
  --> UP018.py:58:1
   |
57 | # These too are literals in spirit
58 | int(+1)
   | ^^^^^^^
59 | int(-1)
60 | float(+1.0)
   |
help: Replace with integer literal
   |
57 | # These too are literals in spirit
   - int(+1)
58 + +1
59 | int(-1)
   |

UP018 [*] Unnecessary `int` call (rewrite as a literal)
  --> UP018.py:59:1
   |
57 | # These too are literals in spirit
58 | int(+1)
59 | int(-1)
   | ^^^^^^^
60 | float(+1.0)
61 | float(-1.0)
   |
help: Replace with integer literal
   |
58 | int(+1)
   - int(-1)
59 + -1
60 | float(+1.0)
   |

UP018 [*] Unnecessary `float` call (rewrite as a literal)
  --> UP018.py:60:1
   |
58 | int(+1)
59 | int(-1)
60 | float(+1.0)
   | ^^^^^^^^^^^
61 | float(-1.0)
   |
help: Replace with float literal
   |
59 | int(-1)
   - float(+1.0)
60 + +1.0
61 | float(-1.0)
   |

UP018 [*] Unnecessary `float` call (rewrite as a literal)
  --> UP018.py:61:1
   |
59 | int(-1)
60 | float(+1.0)
61 | float(-1.0)
   | ^^^^^^^^^^^
   |
help: Replace with float literal
   |
60 | float(+1.0)
   - float(-1.0)
61 + -1.0
62 |
   |

UP018 [*] Unnecessary `int` call (rewrite as a literal)
  --> UP018.py:65:1
   |
64 | # https://github.com/astral-sh/ruff/issues/15859
65 | int(-1) ** 0                 # (-1) ** 0
   | ^^^^^^^
66 | 2 ** int(-1)                 # 2 ** -1
   |
help: Replace with integer literal
   |
64 | # https://github.com/astral-sh/ruff/issues/15859
   - int(-1) ** 0                 # (-1) ** 0
65 + (-1) ** 0                 # (-1) ** 0
66 | 2 ** int(-1)                 # 2 ** -1
   |

UP018 [*] Unnecessary `int` call (rewrite as a literal)
  --> UP018.py:66:6
   |
64 | # https://github.com/astral-sh/ruff/issues/15859
65 | int(-1) ** 0                 # (-1) ** 0
66 | 2 ** int(-1)                 # 2 ** -1
   |      ^^^^^^^
67 |
68 | int(-1)[0]                   # (-1)[0]
   |
help: Replace with integer literal
   |
65 | int(-1) ** 0                 # (-1) ** 0
   - 2 ** int(-1)                 # 2 ** -1
66 + 2 ** (-1)                 # 2 ** -1
67 |
   |

UP018 [*] Unnecessary `int` call (rewrite as a literal)
  --> UP018.py:68:1
   |
66 | 2 ** int(-1)                 # 2 ** -1
67 |
68 | int(-1)[0]                   # (-1)[0]
   | ^^^^^^^
69 | 2[int(-1)]                   # 2[-1]
   |
help: Replace with integer literal
   |
67 |
   - int(-1)[0]                   # (-1)[0]
68 + (-1)[0]                   # (-1)[0]
69 | 2[int(-1)]                   # 2[-1]
   |

UP018 [*] Unnecessary `int` call (rewrite as a literal)
  --> UP018.py:69:3
   |
68 | int(-1)[0]                   # (-1)[0]
69 | 2[int(-1)]                   # 2[-1]
   |   ^^^^^^^
70 |
71 | int(-1)(0)                   # (-1)(0)
   |
help: Replace with integer literal
   |
68 | int(-1)[0]                   # (-1)[0]
   - 2[int(-1)]                   # 2[-1]
69 + 2[(-1)]                   # 2[-1]
70 |
   |

UP018 [*] Unnecessary `int` call (rewrite as a literal)
  --> UP018.py:71:1
   |
69 | 2[int(-1)]                   # 2[-1]
70 |
71 | int(-1)(0)                   # (-1)(0)
   | ^^^^^^^
72 | 2(int(-1))                   # 2(-1)
   |
help: Replace with integer literal
   |
70 |
   - int(-1)(0)                   # (-1)(0)
71 + (-1)(0)                   # (-1)(0)
72 | 2(int(-1))                   # 2(-1)
   |

UP018 [*] Unnecessary `int` call (rewrite as a literal)
  --> UP018.py:72:3
   |
71 | int(-1)(0)                   # (-1)(0)
72 | 2(int(-1))                   # 2(-1)
   |   ^^^^^^^
73 |
74 | float(-1.0).foo              # (-1.0).foo
   |
help: Replace with integer literal
   |
71 | int(-1)(0)                   # (-1)(0)
   - 2(int(-1))                   # 2(-1)
72 + 2((-1))                   # 2(-1)
73 |
   |

UP018 [*] Unnecessary `float` call (rewrite as a literal)
  --> UP018.py:74:1
   |
72 | 2(int(-1))                   # 2(-1)
73 |
74 | float(-1.0).foo              # (-1.0).foo
   | ^^^^^^^^^^^
75 |
76 | await int(-1)                # await (-1)
   |
help: Replace with float literal
   |
73 |
   - float(-1.0).foo              # (-1.0).foo
74 + (-1.0).foo              # (-1.0).foo
75 |
   |

UP018 [*] Unnecessary `int` call (rewrite as a literal)
  --> UP018.py:76:7
   |
74 | float(-1.0).foo              # (-1.0).foo
75 |
76 | await int(-1)                # await (-1)
   |       ^^^^^^^
   |
help: Replace with integer literal
   |
75 |
   - await int(-1)                # await (-1)
76 + await (-1)                # await (-1)
77 |
   |

UP018 [*] Unnecessary `int` call (rewrite as a literal)
  --> UP018.py:79:1
   |
79 | int(+1) ** 0
   | ^^^^^^^
80 | float(+1.0)()
   |
help: Replace with integer literal
   |
78 |
   - int(+1) ** 0
79 + (+1) ** 0
80 | float(+1.0)()
   |

UP018 [*] Unnecessary `float` call (rewrite as a literal)
  --> UP018.py:80:1
   |
79 | int(+1) ** 0
80 | float(+1.0)()
   | ^^^^^^^^^^^
   |
help: Replace with float literal
   |
79 | int(+1) ** 0
   - float(+1.0)()
80 + (+1.0)()
81 |
   |

UP018 [*] Unnecessary `str` call (rewrite as a literal)
  --> UP018.py:83:1
   |
83 | / str(
84 | |     '''Lorem
85 | |     ipsum'''  # Comment
86 | | ).foo
   | |_^
87 |
88 |   # https://github.com/astral-sh/ruff/issues/17606
   |
help: Replace with string literal
   |
82 |
   - str(
   -     '''Lorem
   -     ipsum'''  # Comment
   - ).foo
83 + '''Lorem
84 +     ipsum'''.foo
85 |
   |
note: This is an unsafe fix and may change runtime behavior

UP018 [*] Unnecessary `bool` call (rewrite as a literal)
  --> UP018.py:89:1
   |
88 | # https://github.com/astral-sh/ruff/issues/17606
89 | bool(True)and None
   | ^^^^^^^^^^
90 | int(1)and None
91 | float(1.)and None
   |
help: Replace with boolean literal
   |
88 | # https://github.com/astral-sh/ruff/issues/17606
   - bool(True)and None
89 + True and None
90 | int(1)and None
   |

UP018 [*] Unnecessary `int` call (rewrite as a literal)
  --> UP018.py:90:1
   |
88 | # https://github.com/astral-sh/ruff/issues/17606
89 | bool(True)and None
90 | int(1)and None
   | ^^^^^^
91 | float(1.)and None
92 | bool(True)and()
   |
help: Replace with integer literal
   |
89 | bool(True)and None
   - int(1)and None
90 + 1 and None
91 | float(1.)and None
   |

UP018 [*] Unnecessary `float` call (rewrite as a literal)
  --> UP018.py:91:1
   |
89 | bool(True)and None
90 | int(1)and None
91 | float(1.)and None
   | ^^^^^^^^^
92 | bool(True)and()
   |
help: Replace with float literal
   |
90 | int(1)and None
   - float(1.)and None
91 + 1. and None
92 | bool(True)and()
   |

UP018 [*] Unnecessary `bool` call (rewrite as a literal)
  --> UP018.py:92:1
   |
90 | int(1)and None
91 | float(1.)and None
92 | bool(True)and()
   | ^^^^^^^^^^
   |
help: Replace with boolean literal
   |
91 | float(1.)and None
   - bool(True)and()
92 + True and()
93 |
   |

UP018 [*] Unnecessary `str` call (rewrite as a literal)
   --> UP018.py:99:1
    |
 98 | # UP018 - Extended detections
 99 | str("A" "B")
    | ^^^^^^^^^^^^
100 | str("A" "B").lower()
101 | str(
    |
help: Replace with string literal
    |
98  | # UP018 - Extended detections
    - str("A" "B")
99  + "A" "B"
100 | str("A" "B").lower()
    |

UP018 [*] Unnecessary `str` call (rewrite as a literal)
   --> UP018.py:100:1
    |
 98 | # UP018 - Extended detections
 99 | str("A" "B")
100 | str("A" "B").lower()
    | ^^^^^^^^^^^^
101 | str(
102 |     "A"
    |
help: Replace with string literal
    |
99  | str("A" "B")
    - str("A" "B").lower()
100 + "A" "B".lower()
101 | str(
    |

UP018 [*] Unnecessary `str` call (rewrite as a literal)
   --> UP018.py:101:1
    |
 99 |   str("A" "B")
100 |   str("A" "B").lower()
101 | / str(
102 | |     "A"
103 | |     "B"
104 | | )
    | |_^
105 |   str(object="!")
106 |   complex(1j)
    |
help: Replace with string literal
    |
100 | str("A" "B").lower()
    - str(
    -     "A"
    -     "B"
    - )
101 + ("A"
102 +     "B")
103 | str(object="!")
    |

UP018 [*] Unnecessary `str` call (rewrite as a literal)
   --> UP018.py:105:1
    |
103 |     "B"
104 | )
105 | str(object="!")
    | ^^^^^^^^^^^^^^^
106 | complex(1j)
107 | complex(real=1j)
    |
help: Replace with string literal
    |
104 | )
    - str(object="!")
105 + "!"
106 | complex(1j)
    |

UP018 [*] Unnecessary `complex` call (rewrite as a literal)
   --> UP018.py:106:1
    |
104 | )
105 | str(object="!")
106 | complex(1j)
    | ^^^^^^^^^^^
107 | complex(real=1j)
108 | complex()
    |
help: Replace with complex literal
    |
105 | str(object="!")
    - complex(1j)
106 + 1j
107 | complex(real=1j)
    |

UP018 [*] Unnecessary `complex` call (rewrite as a literal)
   --> UP018.py:107:1
    |
105 | str(object="!")
106 | complex(1j)
107 | complex(real=1j)
    | ^^^^^^^^^^^^^^^^
108 | complex()
109 | complex(0j)
    |
help: Replace with complex literal
    |
106 | complex(1j)
    - complex(real=1j)
107 + 1j
108 | complex()
    |

UP018 [*] Unnecessary `complex` call (rewrite as a literal)
   --> UP018.py:108:1
    |
106 | complex(1j)
107 | complex(real=1j)
108 | complex()
    | ^^^^^^^^^
109 | complex(0j)
110 | complex(real=0j)
    |
help: Replace with complex literal
    |
107 | complex(real=1j)
    - complex()
108 + 0j
109 | complex(0j)
    |

UP018 [*] Unnecessary `complex` call (rewrite as a literal)
   --> UP018.py:109:1
    |
107 | complex(real=1j)
108 | complex()
109 | complex(0j)
    | ^^^^^^^^^^^
110 | complex(real=0j)
111 | (complex(0j)).real
    |
help: Replace with complex literal
    |
108 | complex()
    - complex(0j)
109 + 0j
110 | complex(real=0j)
    |

UP018 [*] Unnecessary `complex` call (rewrite as a literal)
   --> UP018.py:110:1
    |
108 | complex()
109 | complex(0j)
110 | complex(real=0j)
    | ^^^^^^^^^^^^^^^^
111 | (complex(0j)).real
112 | complex(1j).real
    |
help: Replace with complex literal
    |
109 | complex(0j)
    - complex(real=0j)
110 + 0j
111 | (complex(0j)).real
    |

UP018 [*] Unnecessary `complex` call (rewrite as a literal)
   --> UP018.py:111:2
    |
109 | complex(0j)
110 | complex(real=0j)
111 | (complex(0j)).real
    |  ^^^^^^^^^^^
112 | complex(1j).real
113 | complex(real=1j).real
    |
help: Replace with complex literal
    |
110 | complex(real=0j)
    - (complex(0j)).real
111 + (0j).real
112 | complex(1j).real
    |

UP018 [*] Unnecessary `complex` call (rewrite as a literal)
   --> UP018.py:112:1
    |
110 | complex(real=0j)
111 | (complex(0j)).real
112 | complex(1j).real
    | ^^^^^^^^^^^
113 | complex(real=1j).real
    |
help: Replace with complex literal
    |
111 | (complex(0j)).real
    - complex(1j).real
112 + 1j.real
113 | complex(real=1j).real
    |

UP018 [*] Unnecessary `complex` call (rewrite as a literal)
   --> UP018.py:113:1
    |
111 | (complex(0j)).real
112 | complex(1j).real
113 | complex(real=1j).real
    | ^^^^^^^^^^^^^^^^
    |
help: Replace with complex literal
    |
112 | complex(1j).real
    - complex(real=1j).real
113 + 1j.real
    |
