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

Debug output with Python 3.11 could be improved to match 3.10 #1284

Closed
megholm opened this issue Apr 20, 2023 · 2 comments · Fixed by #1370
Closed

Debug output with Python 3.11 could be improved to match 3.10 #1284

megholm opened this issue Apr 20, 2023 · 2 comments · Fixed by #1370
Labels
Backend: WinRT Issues or PRs relating to the WinRT backend enhancement New feature or request

Comments

@megholm
Copy link

megholm commented Apr 20, 2023

  • bleak version: 0.20.2
  • Python version: 3.11.3
  • Operating System: Windows
  • BlueZ version (bluetoothctl -v) in case of Linux:

Description

With Python 3.10.x some lines looked like this:

10:36:52.675 [07396] bleak.ba: [D] session_status_changed_event_handler: id: <_bleak_winrt_Windows_Devices_Bluetooth.BluetoothDeviceId object at 0x000001976F8C8A70>, error: BluetoothError.SUCCESS, status: GattSessionStatus.ACTIVE
 10:36:56.827 [07396] bleak.ba: [D] session_status_changed_event_handler: id: <_bleak_winrt_Windows_Devices_Bluetooth.BluetoothDeviceId object at 0x000001976F8C8C50>, error: BluetoothError.SUCCESS, status: GattSessionStatus.CLOSED

With Python 3.11.x the str(IntEnum) output has changed and this lines become:

 11:34:27.057 [04408] bleak.ba: [D] session_status_changed_event_handler: id: BluetoothLE#BluetoothLEe0:d0:45:43:2e:b0-34:25:b4:a0:b8:0f, error: 0, status: 1
 11:34:31.595 [28732] bleak.ba: [D] session_status_changed_event_handler: id: BluetoothLE#BluetoothLEe0:d0:45:43:2e:b0-34:25:b4:a0:b8:0f, error: 0, status: 0

(Look at error- and status-values).

Consider just adding ".name" to the logger-line:

        def session_status_changed_event_handler(
            sender: GattSession, args: GattSessionStatusChangedEventArgs
        ):
            logger.debug(
                "session_status_changed_event_handler: id: %s, error: %s, status: %s",
                sender.device_id.id,
                args.error.name,
                args.status.name,
            )
            loop.call_soon_threadsafe(handle_session_status_changed, args)
@dlech
Copy link
Collaborator

dlech commented Apr 20, 2023

Perhaps even better would be to change %s to %r so we get the repr which shows both values instead of one or the other?

@dlech dlech added the enhancement New feature or request label Apr 20, 2023
@megholm
Copy link
Author

megholm commented Apr 20, 2023 via email

@dlech dlech added the Backend: WinRT Issues or PRs relating to the WinRT backend label Jul 19, 2023
dlech added a commit that referenced this issue Jul 19, 2023
It has been noted that IntEnum.__str__() has changed in Python 3.11 and
now only prints integers instead of the name of the enum. This changes
all logging messages that use enums in the WinRT backend to use %r for
repr() so that we get both the name and the value.

Fixes: #1284

Also changes uses of str.format() to f-strings and remove uses of
format string from loggers while we are touching this.
dlech added a commit that referenced this issue Jul 20, 2023
It has been noted that IntEnum.__str__() has changed in Python 3.11 and
now only prints integers instead of the name of the enum. This changes
all logging messages that use enums in the WinRT backend to use %r for
repr() so that we get both the name and the value.

Fixes: #1284

Also changes uses of str.format() to f-strings and remove uses of
format string from loggers while we are touching this.
@dlech dlech mentioned this issue Sep 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend: WinRT Issues or PRs relating to the WinRT backend enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants