# Buggy code
def select_device(
    self,
    plugin: "HW_PluginBase",
    handler,
    keystore: "Hardware_KeyStore",
    devices: List["Device"] = None,
) -> "DeviceInfo":
    """Ask the user to select a device to use if there is more than one,
    and return the DeviceInfo for the device."""
    while True:
        infos = self.unpaired_device_infos(handler, plugin, devices)
        if infos:
            break
        msg = _("Please insert your {}").format(plugin.device)
        if keystore.label:
            msg += " ({})".format(keystore.label)
        msg += ". {}\n\n{}".format(
            _(
                "Verify the cable is connected and that "
                "no other application is using it."
            ),
            _("Try to connect again?"),
        )
        if not handler.yes_no_question(msg):
            raise UserCancelled()
        devices = None
    if len(infos) == 1:
        return infos[0]
    # select device by label automatically;
    # but only if not a placeholder label and only if there is no collision
    device_labels = [info.label for info in infos]
    if (
        keystore.label not in PLACEHOLDER_HW_CLIENT_LABELS
        and device_labels.count(keystore.label) == 1
    ):
        for info in infos:
            if info.label == keystore.label:
                return info
    # ask user to select device
    msg = _("Please select which {} device to use:").format(plugin.device)
    descriptions = [
        "{label} ({init}, {transport})".format(
            label=info.label,
            init=(_("initialized") if info.initialized else _("wiped")),
            transport=info.device.transport_ui_string,
        )
        for info in infos
    ]
    c = handler.query_choice(msg, descriptions)
    if c is None:
        raise UserCancelled()
    info = infos[c]
    # save new label
    keystore.set_label(info.label)
    if handler.win.wallet is not None:
        handler.win.wallet.save_keystore()
    return info


# Traceback (AttributeError)
E | gui.qt.installwizard.InstallWizard |
Traceback (most recent call last):
File "/home/matejcik/projekty/prace/electrum/electrum/base_wizard.py", line 540, in create_wallet
password = k.get_password_for_storage_encryption()
File "/home/matejcik/projekty/prace/electrum/electrum/keystore.py", line 768, in get_password_for_storage_encryption
client = self.plugin.get_client(self)
File "/home/matejcik/projekty/prace/electrum/electrum/plugins/trezor/trezor.py", line 184, in get_client
client = devmgr.client_for_keystore(self, handler, keystore, force_pair)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 462, in client_for_keystore
info = self.select_device(plugin, handler, keystore, devices)
File "/home/matejcik/projekty/prace/electrum/electrum/plugin.py", line 584, in select_device
if handler.win.wallet is not None:
AttributeError: 'InstallWizard' object has no attribute 'wallet'

# Fixed code
def select_device(
    self,
    plugin: "HW_PluginBase",
    handler: "HardwareHandlerBase",
    keystore: "Hardware_KeyStore",
    devices: List["Device"] = None,
) -> "DeviceInfo":
    """Ask the user to select a device to use if there is more than one,
    and return the DeviceInfo for the device."""
    while True:
        infos = self.unpaired_device_infos(handler, plugin, devices)
        if infos:
            break
        msg = _("Please insert your {}").format(plugin.device)
        if keystore.label:
            msg += " ({})".format(keystore.label)
        msg += ". {}\n\n{}".format(
            _(
                "Verify the cable is connected and that "
                "no other application is using it."
            ),
            _("Try to connect again?"),
        )
        if not handler.yes_no_question(msg):
            raise UserCancelled()
        devices = None
    if len(infos) == 1:
        return infos[0]
    # select device by label automatically;
    # but only if not a placeholder label and only if there is no collision
    device_labels = [info.label for info in infos]
    if (
        keystore.label not in PLACEHOLDER_HW_CLIENT_LABELS
        and device_labels.count(keystore.label) == 1
    ):
        for info in infos:
            if info.label == keystore.label:
                return info
    # ask user to select device
    msg = _("Please select which {} device to use:").format(plugin.device)
    descriptions = [
        "{label} ({init}, {transport})".format(
            label=info.label,
            init=(_("initialized") if info.initialized else _("wiped")),
            transport=info.device.transport_ui_string,
        )
        for info in infos
    ]
    c = handler.query_choice(msg, descriptions)
    if c is None:
        raise UserCancelled()
    info = infos[c]
    # save new label
    keystore.set_label(info.label)
    wallet = handler.get_wallet()
    if wallet is not None:
        wallet.save_keystore()
    return info