Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ enable=
useless-else-on-loop,
useless-object-inheritance,
async-awaitable-return,
internal-model-tuple-comparison,
6 changes: 5 additions & 1 deletion core/src/apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ def get_features() -> Features:
bootloader_locked=utils.bootloader_locked(),
)

if utils.INTERNAL_MODEL in ("T1B1", "T2B1"):
if (
utils.INTERNAL_MODEL == "T1B1" # pylint: disable=consider-using-in
or utils.INTERNAL_MODEL == "T2B1"
or utils.INTERNAL_MODEL == "T3B1"
):
f.homescreen_format = HomescreenFormat.ToiG
else:
f.homescreen_format = HomescreenFormat.Jpeg
Expand Down
10 changes: 8 additions & 2 deletions core/src/apps/bitcoin/sign_tx/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,14 @@ async def confirm_output(
if output.address_n and not output.multisig:
from trezor import utils

# Showing the account string only for T2B1 model
show_account_str = utils.INTERNAL_MODEL == "T2B1"
# Showing the account string only for model_tr layout
# TODO expose layout_type so that we can check for it, instead of listing
# all models that use the layout?
show_account_str = (
# pylint: disable-next=consider-using-in
utils.INTERNAL_MODEL == "T2B1"
or utils.INTERNAL_MODEL == "T3B1"
)
script_type = CHANGE_OUTPUT_TO_INPUT_SCRIPT_TYPES[output.script_type]
address_label = (
address_n_to_name(
Expand Down
9 changes: 7 additions & 2 deletions core/src/apps/debug/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,16 @@ async def dispatch_DebugLinkDecision(msg: DebugLinkDecision) -> None:
if (
x is not None
and y is not None
and utils.INTERNAL_MODEL in ("T2T1", "T3T1", "D001")
and utils.INTERNAL_MODEL # pylint: disable=internal-model-tuple-comparison
in ("T2T1", "T3T1", "D001")
):
click_chan.publish((debug_events.last_event, x, y, msg.hold_ms))
# Button devices press specific button
elif msg.physical_button is not None and utils.INTERNAL_MODEL in ("T2B1",):
elif (
msg.physical_button is not None
and utils.INTERNAL_MODEL # pylint: disable=internal-model-tuple-comparison
in ("T2B1", "T3B1")
):
button_chan.publish(
(debug_events.last_event, msg.physical_button, msg.hold_ms)
)
Expand Down
5 changes: 3 additions & 2 deletions core/src/apps/management/recovery_device/homescreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ async def _continue_recovery_process() -> Success:
if is_first_step:
# If we are starting recovery, ask for word count first...
# _request_word_count
# For TT, just continuing straight to word count keyboard
if utils.INTERNAL_MODEL == "T2B1":
# For others than model_tr, just continue straight to word count keyboard
# pylint: disable-next=consider-using-in
if utils.INTERNAL_MODEL == "T2B1" or utils.INTERNAL_MODEL == "T3B1":
await layout.homescreen_dialog(
TR.buttons__continue, TR.recovery__num_of_words
)
Expand Down
8 changes: 5 additions & 3 deletions core/src/apps/workflow_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ def _find_message_handler_module(msg_type: int) -> str:
return "apps.management.reboot_to_bootloader"

if (
utils.INTERNAL_MODEL in ("T2B1", "T3T1")
and msg_type == MessageType.ShowDeviceTutorial
):
# pylint: disable-next=consider-using-in
utils.INTERNAL_MODEL == "T2B1"
or utils.INTERNAL_MODEL == "T3B1"
or utils.INTERNAL_MODEL == "T3T1"
) and msg_type == MessageType.ShowDeviceTutorial:
return "apps.management.show_tutorial"

if utils.USE_BACKLIGHT and msg_type == MessageType.SetBrightness:
Expand Down
7 changes: 5 additions & 2 deletions core/src/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@

# have to use "==" over "in (list)" so that it can be statically replaced
# with the correct value during the build process
# pylint: disable-next=consider-using-in
if utils.INTERNAL_MODEL == "T2T1" or utils.INTERNAL_MODEL == "T2B1":
if ( # pylint: disable-next=consider-using-in
utils.INTERNAL_MODEL == "T2T1"
or utils.INTERNAL_MODEL == "T2B1"
or utils.INTERNAL_MODEL == "T3B1"
):
_WELCOME_SCREEN_MS = 1000 # how long do we want to show welcome screen (minimum)
else:
_WELCOME_SCREEN_MS = 0
Expand Down
7 changes: 6 additions & 1 deletion core/src/trezor/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ def refresh() -> None:


# in both debug and production, emulator needs to draw the screen explicitly
if utils.EMULATOR or utils.INTERNAL_MODEL in ("T1B1", "T2B1"):
if (
utils.EMULATOR
or utils.INTERNAL_MODEL == "T1B1"
or utils.INTERNAL_MODEL == "T2B1"
or utils.INTERNAL_MODEL == "T3B1"
):
loop.after_step_hook = refresh


Expand Down
4 changes: 2 additions & 2 deletions core/tests/test_apps.bitcoin.signtx_decred.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from common import * # isort:skip

if utils.INTERNAL_MODEL not in ("T2B1", "T3T1"):
if utils.INTERNAL_MODEL in ("T1B1", "T2T1"):
from trezor.crypto import bip39
from trezor.enums import AmountUnit, OutputScriptType
from trezor.enums.RequestType import TXFINISHED, TXINPUT, TXMETA, TXOUTPUT
Expand Down Expand Up @@ -405,5 +405,5 @@ def test_purchase_ticket(self):


if __name__ == "__main__":
if utils.INTERNAL_MODEL not in ("T2B1", "T3T1"):
if utils.INTERNAL_MODEL in ("T1B1", "T2T1"):
unittest.main()
2 changes: 1 addition & 1 deletion core/tests/test_apps.common.coins.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_altcoins(self):
("ZEC", "Zcash", 7352),
("TAZ", "Zcash Testnet", 7461),
]
if utils.INTERNAL_MODEL not in ("T2B1", "T3T1"):
if utils.INTERNAL_MODEL in ("T1B1", "T2T1"):
ref.extend(
[
("NMC", "Namecoin", 52),
Expand Down
4 changes: 2 additions & 2 deletions python/src/trezorlib/debuglink.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ def visible_screen(self) -> str:
********************
ICON_CANCEL, -, CONFIRM
"""
title_separator = f"\n{20*'-'}\n"
btn_separator = f"\n{20*'*'}\n"
title_separator = f"\n{20 * '-'}\n"
btn_separator = f"\n{20 * '*'}\n"

visible = ""
if self.title():
Expand Down
48 changes: 46 additions & 2 deletions tools/trezor-pylint-plugin/trezor_pylint_plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from astroid import AsyncFunctionDef
from astroid import nodes
from pylint.checkers import BaseChecker
from pylint.checkers.utils import check_messages
from pylint.interfaces import IAstroidChecker
Expand All @@ -18,12 +18,56 @@ class AsyncAwaitableChecker(BaseChecker):
}

@check_messages("async-awaitable-return")
def visit_asyncfunctiondef(self, node: AsyncFunctionDef):
def visit_asyncfunctiondef(self, node: nodes.AsyncFunctionDef):
# Check if the return type is explicitly an Awaitable
if node.returns and "Awaitable" in node.returns.as_string():
self.add_message("async-awaitable-return", node=node, args=(node.name,))


class InternalModelComparisonChecker(BaseChecker):
"""Check that utils.INTERNAL_MODEL is only compared using '==' or '!='.

This is because the static replacer does not support 'in' or 'not in' comparisons,
so the comparison is compiled into all models and performed at runtime. This is
typically not what you want.

When multiple comparisons are necessary, you may need to silence another
pylint warning: # pylint: disable=consider-using-in
"""

__implements__ = IAstroidChecker

name = "internal-model-comparison-checker"
priority = -1
msgs = {
"W9998": (
"Only compare INTERNAL_MODEL using '==' or '!='.",
"internal-model-tuple-comparison",
"Used when utils.INTERNAL_MODEL is compared using 'in' or 'not in' with a tuple.",
),
}

@staticmethod
def _is_internal_model(node):
return (
isinstance(node, nodes.Attribute)
and node.attrname == "INTERNAL_MODEL"
and isinstance(node.expr, nodes.Name)
and node.expr.name == "utils"
)

@check_messages("internal-model-tuple-comparison")
def visit_compare(self, node: nodes.Compare):
if not self._is_internal_model(node.left):
return
if len(node.ops) != 1:
return
op, _right = node.ops[0]
if op in ("in", "not in"):
self.add_message("internal-model-tuple-comparison", node=node)


def register(linter):
"""Required method to auto register this checker."""
linter.register_checker(AsyncAwaitableChecker(linter))
linter.register_checker(InternalModelComparisonChecker(linter))
Loading