Skip to content

Commit

Permalink
machine.linux: Fix a mypy error
Browse files Browse the repository at this point in the history
Mypy was complaining that

    tbot/machine/linux/build.py:65:
    error: Argument 2 to "exec0" of "LinuxShell" has incompatible type
    "Path[H@__init__]"; expected "Union[str, Special[H@enable],
    Path[H@enable]]"

Tweak the code so mypy correctly understands the relationship between
types.
  • Loading branch information
Rahix committed Aug 1, 2024
1 parent ad43278 commit 7926f7d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions tbot/machine/linux/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ def enable(self, host: "Builder") -> None:
pass


H = typing.TypeVar("H", bound="Builder")


class EnvScriptToolchain(Toolchain):
"""
Toolchain that is initialized using an env script (e.g. yocto toolchain).
Expand All @@ -52,15 +49,15 @@ def toolchains(self):
}
"""

def __init__(self, path: path.Path[H]) -> None:
def __init__(self, path: "path.Path[Builder]") -> None:
"""
Create a new EnvScriptToolchain.
:param linux.Path path: Path to the env script
"""
self.env_script = path

def enable(self, host: H) -> None:
def enable(self, host: "Builder") -> None:
host.exec0("unset", "LD_LIBRARY_PATH")
host.exec0("source", self.env_script)

Expand All @@ -85,7 +82,7 @@ def __init__(self, arch: str, prefix: str) -> None:
self.arch = arch
self.prefix = prefix

def enable(self, host: H) -> None:
def enable(self, host: "Builder") -> None:
host.env("ARCH", self.arch)
host.env("CROSS_COMPILE", self.prefix)

Expand Down
2 changes: 1 addition & 1 deletion tbot/tc/selftest/tc/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def toolchains(self) -> typing.Dict[str, linux.build.Toolchain]:
"""Return toolchains available on this host."""
return {
"selftest-toolchain": linux.build.EnvScriptToolchain(
self.workdir / ".selftest-toolchain.sh"
self.workdir / ".selftest-toolchain.sh" # type: ignore
)
}

Expand Down

0 comments on commit 7926f7d

Please sign in to comment.