# Buggy code
def create_wallet(self):
    encrypt_keystore = any(k.may_have_password() for k in self.keystores)
    # note: the following condition ("if") is duplicated logic from
    # wallet.get_available_storage_encryption_version()
    if self.wallet_type == "standard" and isinstance(
        self.keystores[0], Hardware_KeyStore
    ):
        # offer encrypting with a pw derived from the hw device
        k = self.keystores[0]  # type: Hardware_KeyStore
        try:
            k.handler = self.plugin.create_handler(self)
            password = k.get_password_for_storage_encryption()
        except UserCancelled:
            devmgr = self.plugins.device_manager
            devmgr.unpair_xpub(k.xpub)
            self.choose_hw_device()
            return
        except BaseException as e:
            self.logger.exception("")
            self.show_error(str(e))
            return
        self.request_storage_encryption(
            run_next=lambda encrypt_storage: self.on_password(
                password,
                encrypt_storage=encrypt_storage,
                storage_enc_version=StorageEncryptionVersion.XPUB_PASSWORD,
                encrypt_keystore=False,
            )
        )
    else:
        # reset stack to disable 'back' button in password dialog
        self.reset_stack()
        # prompt the user to set an arbitrary password
        self.request_password(
            run_next=lambda password, encrypt_storage: self.on_password(
                password,
                encrypt_storage=encrypt_storage,
                storage_enc_version=StorageEncryptionVersion.USER_PASSWORD,
                encrypt_keystore=encrypt_keystore,
            ),
            force_disable_encrypt_cb=not encrypt_keystore,
        )


# 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 create_wallet(self):
    encrypt_keystore = any(k.may_have_password() for k in self.keystores)
    # note: the following condition ("if") is duplicated logic from
    # wallet.get_available_storage_encryption_version()
    if self.wallet_type == "standard" and isinstance(
        self.keystores[0], Hardware_KeyStore
    ):
        # offer encrypting with a pw derived from the hw device
        k = self.keystores[0]  # type: Hardware_KeyStore
        assert isinstance(self.plugin, HW_PluginBase)
        try:
            k.handler = self.plugin.create_handler(self)
            password = k.get_password_for_storage_encryption()
        except UserCancelled:
            devmgr = self.plugins.device_manager
            devmgr.unpair_xpub(k.xpub)
            self.choose_hw_device()
            return
        except BaseException as e:
            self.logger.exception("")
            self.show_error(str(e))
            return
        self.request_storage_encryption(
            run_next=lambda encrypt_storage: self.on_password(
                password,
                encrypt_storage=encrypt_storage,
                storage_enc_version=StorageEncryptionVersion.XPUB_PASSWORD,
                encrypt_keystore=False,
            )
        )
    else:
        # reset stack to disable 'back' button in password dialog
        self.reset_stack()
        # prompt the user to set an arbitrary password
        self.request_password(
            run_next=lambda password, encrypt_storage: self.on_password(
                password,
                encrypt_storage=encrypt_storage,
                storage_enc_version=StorageEncryptionVersion.USER_PASSWORD,
                encrypt_keystore=encrypt_keystore,
            ),
            force_disable_encrypt_cb=not encrypt_keystore,
        )