From 06c55481863bdd09153937e2e23fa3c2034e467b Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Mon, 9 Oct 2023 17:17:00 -0700 Subject: [PATCH] Fix issues passing mypy --strict (#21) --- .github/workflows/ci.yml | 6 ------ .pre-commit-config.yaml | 6 ++++++ binharness/localenvironment.py | 3 ++- binharness/types/io.py | 26 +++++++++++++------------- pyproject.toml | 2 -- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ebb1acf..faff579 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,11 +19,5 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install binharness run: pip install -e .[dev] - - name: Run ruff - run: ruff . - - name: Run black - run: black --check . - - name: Run mypy - run: mypy binharness - name: Run pytest run: pytest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 12a3a03..576e7c1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,6 +24,12 @@ repos: - id: rst-directive-colons - id: rst-inline-touching-normal +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.5.1 + hooks: + - id: mypy + args: [--strict] + - repo: https://github.com/abravalheri/validate-pyproject rev: v0.14 hooks: diff --git a/binharness/localenvironment.py b/binharness/localenvironment.py index 23b08fb..d95864f 100644 --- a/binharness/localenvironment.py +++ b/binharness/localenvironment.py @@ -70,7 +70,7 @@ def get_tempdir(self: LocalEnvironment) -> Path: class LocalProcess(Process): """A process running in a local environment.""" - popen: subprocess.Popen + popen: subprocess.Popen[bytes] def __init__( self: LocalProcess, @@ -88,6 +88,7 @@ def __init__( stderr=subprocess.PIPE, env=env, cwd=cwd, + universal_newlines=False, ) @property diff --git a/binharness/types/io.py b/binharness/types/io.py index 8eabe60..80dfa21 100644 --- a/binharness/types/io.py +++ b/binharness/types/io.py @@ -7,42 +7,42 @@ class IO(Protocol[AnyStr]): """A file-like object.""" - def close(self: IO) -> None: + def close(self: IO[AnyStr]) -> None: """Close the file.""" @property - def closed(self: IO) -> bool: + def closed(self: IO[AnyStr]) -> bool: """Whether the file is closed.""" - def flush(self: IO) -> None: + def flush(self: IO[AnyStr]) -> None: """Flush the file.""" - def read(self: IO, n: int = -1) -> AnyStr: + def read(self: IO[AnyStr], n: int = -1) -> AnyStr: """Read n bytes from the file.""" - def readable(self: IO) -> bool: + def readable(self: IO[AnyStr]) -> bool: """Whether the file is readable.""" - def readline(self: IO, limit: int = -1) -> AnyStr: + def readline(self: IO[AnyStr], limit: int = -1) -> AnyStr: """Read a line from the file.""" - def readlines(self: IO, hint: int = -1) -> list[AnyStr]: + def readlines(self: IO[AnyStr], hint: int = -1) -> list[AnyStr]: """Read lines from the file.""" - def seek(self: IO, offset: int, whence: int = 0) -> int | None: + def seek(self: IO[AnyStr], offset: int, whence: int = 0) -> int | None: """Seek to a position in the file.""" - def seekable(self: IO) -> bool: + def seekable(self: IO[AnyStr]) -> bool: """Whether the file is seekable.""" - def tell(self: IO) -> int: + def tell(self: IO[AnyStr]) -> int: """Get the current position in the file.""" - def writable(self: IO) -> bool: + def writable(self: IO[AnyStr]) -> bool: """Whether the file is writable.""" - def write(self: IO, s: AnyStr) -> int | None: + def write(self: IO[AnyStr], s: AnyStr) -> int | None: """Write to the file.""" - def writelines(self: IO, lines: list[AnyStr]) -> None: + def writelines(self: IO[AnyStr], lines: list[AnyStr]) -> None: """Write lines to the file.""" diff --git a/pyproject.toml b/pyproject.toml index dbe543d..1c341f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,13 +19,11 @@ dynamic = ["version"] dev = [ "black>=23.3.0", "coverage[toml]>=7.2.3", - "mock-ssh-server>=0.9.1", "mypy>=1.2.0", "pre-commit>=3.2.2", "pytest>=7.3.1", "pytest-cov>=4.0.0", "ruff>=0.0.262", - "types-paramiko>=3.0.0.7", ] [project.urls]