treefmt v2.5.0ERRO formatter | ruff-check: failed to apply with options '[check --fix]': exit status 1 EXE001 Shebang is present but file is not executable --> doc/generate_command_reference.py:1:1 | 1 | #!/usr/bin/env python | ^^^^^^^^^^^^^^^^^^^^^ 2 | 3 | import os.path | BLE001 Do not catch blind exception: `Exception` --> examples/asyncio_example.py:15:12 | 13 | try: 14 | await client.connect("localhost", 6600) 15 | except Exception as e: | ^^^^^^^^^ 16 | print("Connection failed:", e) 17 | return | BLE001 Do not catch blind exception: `Exception` --> examples/asyncio_example.py:23:12 | 21 | try: 22 | status = await client.status() 23 | except Exception as e: | ^^^^^^^^^ 24 | print("Status error:", e) 25 | return | BLE001 Do not catch blind exception: `Exception` --> examples/asyncio_example.py:47:12 | 45 | try: 46 | await client.addid() 47 | except Exception as e: | ^^^^^^^^^ 48 | print("An erroneous command, as expected, raised:", e) | BLE001 Do not catch blind exception: `Exception` --> examples/asyncio_example.py:53:12 | 51 | async for x in client.plchangesposid(): 52 | print("Why does this work?") 53 | except Exception as e: | ^^^^^^^^^ 54 | print("An erroneous asynchronously looped command, as expected, raised:", e) | EXE001 Shebang is present but file is not executable --> examples/coverart.py:1:1 | 1 | #!/usr/bin/env python | ^^^^^^^^^^^^^^^^^^^^^ 2 | 3 | # IMPORTS | TRY201 Use `raise` without specifying exception name --> examples/coverart.py:39:15 | 37 | # mpd.base.CommandError: [50@0] {albumart} No file exists 38 | if error.errno is not FailureResponseCode.NO_EXIST: 39 | raise error | ^^^^^ 40 | 41 | try: | help: Remove exception name EXE001 Shebang is present but file is not executable --> examples/errorhandling.py:1:1 | 1 | #! /usr/bin/env python | ^^^^^^^^^^^^^^^^^^^^^^ 2 | # 3 | # Introduction | RUF059 Unpacked variable `errno` is never used --> examples/errorhandling.py:30:13 | 28 | # Catch socket errors 29 | except OSError as err: 30 | errno, strerror = err | ^^^^^ 31 | raise PollerError("Could not connect to '%s': %s" % (self._host, strerror)) | help: Prefix it with an underscore or any other dummy variable pattern UP031 Use format specifiers instead of percent format --> examples/errorhandling.py:31:31 | 29 | except OSError as err: 30 | errno, strerror = err 31 | raise PollerError("Could not connect to '%s': %s" % (self._host, strerror)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 32 | 33 | # Catch all other possible errors | help: Replace with format specifiers UP031 Use format specifiers instead of percent format --> examples/errorhandling.py:38:31 | 36 | # they are instead of ignoring them. 37 | except MPDError as e: 38 | raise PollerError("Could not connect to '%s': %s" % (self._host, e)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 39 | 40 | if self._password: | help: Replace with format specifiers UP031 Use format specifiers instead of percent format --> examples/errorhandling.py:49:21 | 47 | # split into errno, offset, command and msg. 48 | raise PollerError( 49 | / "Could not connect to '%s': " 50 | | "password commmand failed: [%d] %s" % (self._host, e.errno, e.msg) | |_______________________________________________________^ 51 | ) | help: Replace with format specifiers UP031 Use format specifiers instead of percent format --> examples/errorhandling.py:56:21 | 54 | except (OSError, MPDError) as e: 55 | raise PollerError( 56 | / "Could not connect to '%s': " 57 | | "error with password command: %s" % (self._host, e) | |_______________________________________________________________________^ 58 | ) | help: Replace with format specifiers UP031 Use format specifiers instead of percent format --> examples/errorhandling.py:94:35 | 92 | # Reconnecting failed 93 | except PollerError as e: 94 | raise PollerError("Reconnecting failed: %s" % e) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 95 | 96 | try: | help: Replace with format specifiers UP031 Use format specifiers instead of percent format --> examples/errorhandling.py:101:35 | 99 | # Failed again, just give up 100 | except (OSError, MPDError) as e: 101 | raise PollerError("Couldn't retrieve current song: %s" % e) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 102 | 103 | # Hurray! We got the current song without any errors! | help: Replace with format specifiers UP031 Use format specifiers instead of percent format --> examples/errorhandling.py:126:15 | 124 | # Catch fatal poller errors 125 | except PollerError as e: 126 | print("Fatal poller error: %s" % e, file=sys.stderr) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 127 | sys.exit(1) | help: Replace with format specifiers BLE001 Do not catch blind exception: `Exception` --> examples/errorhandling.py:130:12 | 129 | # Catch all other non-exit errors 130 | except Exception as e: | ^^^^^^^^^ 131 | print("Unexpected exception: %s" % e, file=sys.stderr) 132 | sys.exit(1) | UP031 Use format specifiers instead of percent format --> examples/errorhandling.py:131:15 | 129 | # Catch all other non-exit errors 130 | except Exception as e: 131 | print("Unexpected exception: %s" % e, file=sys.stderr) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 132 | sys.exit(1) | help: Replace with format specifiers BLE001 Do not catch blind exception: `Exception` --> examples/errorhandling.py:135:12 | 134 | # Catch the remaining exit errors 135 | except Exception: | ^^^^^^^^^ 136 | sys.exit(0) | B025 try-except block with duplicate exception `Exception` --> examples/errorhandling.py:135:12 | 134 | # Catch the remaining exit errors 135 | except Exception: | ^^^^^^^^^ 136 | sys.exit(0) | EXE001 Shebang is present but file is not executable --> examples/helloworld.py:1:1 | 1 | #!/usr/bin/python | ^^^^^^^^^^^^^^^^^ 2 | import mpd | UP031 Use format specifiers instead of percent format --> examples/helloworld.py:8:11 | 7 | for entry in client.lsinfo("/"): 8 | print("%s" % entry) | ^^^^^^^^^^^^ 9 | for key, value in client.status().items(): 10 | print("%s: %s" % (key, value)) | help: Replace with format specifiers UP031 Use format specifiers instead of percent format --> examples/helloworld.py:10:11 | 8 | print("%s" % entry) 9 | for key, value in client.status().items(): 10 | print("%s: %s" % (key, value)) | ^^^^^^^^^^^^^^^^^^^^^^^ help: Replace with format specifiers EXE001 Shebang is present but file is not executable --> examples/randomqueue.py:1:1 | 1 | #!/usr/bin/env python | ^^^^^^^^^^^^^^^^^^^^^ 2 | 3 | # IMPORTS | EXE001 Shebang is present but file is not executable --> examples/stats.py:1:1 | 1 | #!/usr/bin/env python | ^^^^^^^^^^^^^^^^^^^^^ 2 | 3 | # IMPORTS | EXE001 Shebang is present but file is not executable --> examples/stickers.py:26:1 | 24 | # sticker.py 25 | 26 | #! /usr/bin/env python | ^^^^^^^^^^^^^^^^^^^^^^ 27 | 28 | from optparse import OptionParser | EXE005 Shebang should be at the beginning of the file --> examples/stickers.py:26:1 | 24 | # sticker.py 25 | 26 | #! /usr/bin/env python | ^^^^^^^^^^^^^^^^^^^^^^ 27 | 28 | from optparse import OptionParser | UP031 Use format specifiers instead of percent format --> examples/stickers.py:74:22 | 73 | if len(args) < 1: 74 | parser.error("no action specified, must be one of: %s" % " ".join(ACTIONS)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 75 | action = args.pop(0) | help: Replace with format specifiers UP031 Use format specifiers instead of percent format --> examples/stickers.py:78:22 | 77 | if action not in ACTIONS: 78 | parser.error("action must be one of: %s" % " ".join(ACTIONS)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 79 | 80 | if len(args) < 1: | help: Replace with format specifiers UP031 Use format specifiers instead of percent format --> examples/stickers.py:102:13 | 100 | except OSError as e: 101 | print( 102 | "%s: error with connection to MPD: %s" % (parser.get_prog_name(), e[1]), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 103 | file=stderr, 104 | ) | help: Replace with format specifiers UP031 Use format specifiers instead of percent format --> examples/stickers.py:107:13 | 105 | except MPDError as e: 106 | print( 107 | "%s: error executing action: %s" % (parser.get_prog_name(), e), file=stderr | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 108 | ) | help: Replace with format specifiers TRY002 Create your own exception --> mpd/__init__.py:37:19 | 35 | class MPDProtocolDummy: 36 | def __init__(self) -> None: 37 | raise Exception("No twisted module found") | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 38 | 39 | MPDProtocol = MPDProtocolDummy # type: ignore | BLE001 Do not catch blind exception: `Exception` --> mpd/asyncio.py:157:16 | 155 | async for r in self: 156 | result.append(r) 157 | except Exception as e: | ^^^^^^^^^ 158 | self.set_exception(e) 159 | else: | C405 Unnecessary list literal (rewrite as a set literal) --> mpd/asyncio.py:339:38 | 337 | # The presumably most quiet subsystem -- in this case, 338 | # idle is only used to keep the connection alive. 339 | subsystems = set(["database"]) | ^^^^^^^^^^^^^^^^^ 340 | 341 | # Careful: There can't be any await points between the | help: Rewrite as a set literal B006 Do not use mutable data structures for argument defaults --> mpd/asyncio.py:472:33 | 470 | self, 471 | lines: "asyncio.Queue[str]", 472 | delimiters: list[str] = [], | ^^ 473 | lookup_delimiter: bool = False, 474 | ) -> AsyncIterator[dict[str, str]]: | help: Replace with `None`; initialize within function T100 Trace found: `breakpoint` used --> mpd/asyncio.py:546:17 | 544 | args[-1] = len(data) 545 | if len(data) > size: 546 | breakpoint() | ^^^^^^^^^^^^ 547 | raise CommandListError("Binary data announced size exceeded") 548 | elif len(data) == size: | ISC004 Unparenthesized implicit string concatenation in collection --> mpd/asyncio.py:618:25 | 616 | except asyncio.QueueFull as e: 617 | e.args = ( 618 | / "Command queue overflowing; this indicates the" 619 | | " application sending commands in an uncontrolled" 620 | | " fashion without awaiting them, and typically" 621 | | " indicates a memory leak.", | |___________________________________________________^ 622 | ) 623 | # While we *could* indicate to the queued result that it has | help: Did you forget a comma? help: Wrap implicitly concatenated strings in parentheses BLE001 Do not catch blind exception: `BaseException` --> mpd/asyncio.py:639:24 | 637 | try: 638 | self._write_command(result._command, result._args) 639 | except BaseException as e: | ^^^^^^^^^^^^^ 640 | self.disconnect() 641 | result.set_exception(e) | B006 Do not use mutable data structures for argument defaults --> mpd/asyncio.py:650:52 | 648 | # commands that just work differently 649 | async def idle( 650 | self, subsystems: list[str] | tuple[str] = [] | ^^ 651 | ) -> AsyncIterator[list[str] | Exception]: 652 | if self.__idle_consumers is None: | help: Replace with `None`; initialize within function UP031 Use format specifiers instead of percent format --> mpd/base.py:127:17 | 125 | if kwargs: 126 | raise AttributeError( 127 | "mpd_commands() got unexpected keyword arguments %s" % ",".join(kwargs) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 128 | ) | help: Replace with format specifiers B006 Do not use mutable data structures for argument defaults --> mpd/base.py:213:33 | 211 | self, 212 | lines: Iterable[str], 213 | delimiters: list[str] = [], | ^^ 214 | lookup_delimiter: bool = False, 215 | ) -> Iterator[dict[str, str]]: | help: Replace with `None`; initialize within function RUF059 Unpacked variable `key` is never used --> mpd/base.py:419:9 | 417 | @mpd_commands("sticker get") 418 | def _parse_sticker(self, lines: list[str]) -> str: 419 | key, value = list(self._parse_raw_stickers(lines))[0] | ^^^ 420 | return value | help: Prefix it with an underscore or any other dummy variable pattern RUF015 Prefer `next(iter(self._parse_raw_stickers(lines)))` over single element slice --> mpd/base.py:419:22 | 417 | @mpd_commands("sticker get") 418 | def _parse_sticker(self, lines: list[str]) -> str: 419 | key, value = list(self._parse_raw_stickers(lines))[0] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 420 | return value | help: Replace with `next(iter(self._parse_raw_stickers(lines)))` B006 Do not use mutable data structures for argument defaults --> mpd/base.py:440:59 | 439 | def collect( 440 | cls: Any, callbacks: dict[str, tuple[Any, Any]] = {} | ^^ 441 | ) -> dict[str, tuple[Any, Any]]: 442 | """Collect MPD command callbacks from given class. | help: Replace with `None`; initialize within function PERF102 When using only the values of a dict use the `values()` method --> mpd/base.py:456:24 | 454 | return callbacks 455 | 456 | for name, value in collect(cls).items(): | ^^^^^^^^^^^^^^^^^^ 457 | callback, from_ = value 458 | for command in callback.mpd_commands: | help: Replace `.items()` with `.values()` RUF059 Unpacked variable `from_` is never used --> mpd/base.py:457:19 | 456 | for name, value in collect(cls).items(): 457 | callback, from_ = value | ^^^^^ 458 | for command in callback.mpd_commands: 459 | cls.add_command(command, callback) | help: Prefix it with an underscore or any other dummy variable pattern RUF012 Mutable default value for class attribute --> mpd/base.py:506:30 | 504 | idletimeout = None 505 | _timeout = None 506 | _wrap_iterator_parsers = [ | ______________________________^ 507 | | MPDClientBase._parse_list, 508 | | MPDClientBase._parse_list_groups, 509 | | MPDClientBase._parse_playlist, 510 | | MPDClientBase._parse_changes, 511 | | MPDClientBase._parse_songs, 512 | | MPDClientBase._parse_mounts, 513 | | MPDClientBase._parse_neighbors, 514 | | MPDClientBase._parse_partitions, 515 | | MPDClientBase._parse_playlists, 516 | | MPDClientBase._parse_database, 517 | | MPDClientBase._parse_messages, 518 | | MPDClientBase._parse_outputs, 519 | | MPDClientBase._parse_plugins, 520 | | ] | |_____^ 521 | 522 | def __init__(self, use_unicode: bool | None = None) -> None: | help: Consider initializing in `__init__` or annotating with `typing.ClassVar` B006 Do not use mutable data structures for argument defaults --> mpd/base.py:567:62 | 565 | raise e.with_traceback(sys.exc_info()[2]) 566 | 567 | def _write_command(self, command: str, args: list[Any] = []) -> None: | ^^ 568 | parts = [command] 569 | for arg in args: | help: Replace with `None`; initialize within function UP031 Use format specifiers instead of percent format --> mpd/base.py:648:25 | 646 | self.disconnect() 647 | raise ConnectionError( 648 | / "Connection lost while reading binary data: " 649 | | "expected %d bytes, got %d" % (chunk_size, len(value)) | |___________________________________________________^ 650 | ) | help: Replace with format specifiers UP028 Replace `yield` over `for` loop with `yield from` --> mpd/base.py:735:13 | 733 | ) -> Iterator[dict[str, str]]: 734 | try: 735 | / for item in iterator: 736 | | yield item | |__________________________^ 737 | finally: 738 | self._iterating = False | help: Replace with `yield from` RUF059 Unpacked variable `canonname` is never used --> mpd/base.py:775:34 | 773 | socket.AI_ADDRCONFIG, 774 | ): 775 | af, socktype, proto, canonname, sa = res | ^^^^^^^^^ 776 | sock = None 777 | try: | help: Prefix it with an underscore or any other dummy variable pattern UP031 Use format specifiers instead of percent format --> mpd/tests.py:1269:24 | 1267 | next_write = self._expectations[0][0][0] 1268 | except IndexError: 1269 | self.error("Data written to mock even though none expected: %r" % data) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1270 | if next_write == data: 1271 | self._expectations[0][0].pop(0) | help: Replace with format specifiers UP031 Use format specifiers instead of percent format --> mpd/tests.py:1274:24 | 1272 | self._feed() 1273 | else: 1274 | self.error("Mock got %r, expected %r" % (data, next_write)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1275 | 1276 | def close(self) -> None: | help: Replace with format specifiers B006 Do not use mutable data structures for argument defaults --> mpd/twisted.py:153:47 | 151 | @lock 152 | def _execute( 153 | self, command: str, args: list[str] = [], parser: Callable | None = None | ^^ 154 | ) -> defer.Deferred: 155 | # close or kill command in command list not allowed | help: Replace with `None`; initialize within function B006 Do not use mutable data structures for argument defaults --> mpd/twisted.py:178:63 | 176 | return deferred 177 | 178 | def _create_command(self, command: str, args: list[str] = []) -> bytes: | ^^ 179 | # XXX: this function should be generalized in future. There exists 180 | # almost identical code in ``MPDClient._write_command``, with the | help: Replace with `None`; initialize within function B006 Do not use mutable data structures for argument defaults --> mpd/twisted.py:195:62 | 193 | return " ".join(parts).encode("utf-8") 194 | 195 | def _write_command(self, command: str, args: list[str] = []) -> None: | ^^ 196 | self.sendLine(self._create_command(command, args)) | help: Replace with `None`; initialize within function Found 298 errors (242 fixed, 56 remaining). No fixes available (33 hidden fixes can be enabled with the `--unsafe-fixes` option). traversed 45 files emitted 18 files for processing formatted 0 files (14 changed) in 145ms Error: failed to finalise formatting: formatting failures detected