Im my opinion it would nice if the method does not raise any exception but return None in case of an error.
This would largely correspond to the C implementation, which returns -1 in case of error and 0 in case of success.
In my suggestion -1 would be None and 0 would be the name of the socket.
In my opinion, the compositor should be responsible for responding to an error, not pywayland.
See also https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/486 why it might make sense to try multiple socket names.
If the method does not raise any errors, the following implementation would be possible without catching a generic Exception:
for i in range(1, 33):
if display.add_socket(f'wayland-{i}'):
break
Im my opinion it would nice if the method does not raise any exception but return
Nonein case of an error.This would largely correspond to the C implementation, which returns
-1in case of error and0in case of success.In my suggestion
-1would beNoneand0would be the name of the socket.In my opinion, the compositor should be responsible for responding to an error, not pywayland.
See also https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/486 why it might make sense to try multiple socket names.
If the method does not raise any errors, the following implementation would be possible without catching a generic Exception: