From 5b2b4e38125ab013060bfca63f70c10054488cff Mon Sep 17 00:00:00 2001 From: Eskild Schroll-Fleischer Date: Sat, 21 Dec 2024 23:13:42 +0100 Subject: [PATCH] Type check with mypy. Lint with ruff. --- README.md | 2 ++ pyproject.toml | 2 ++ reloading/reloading.py | 2 +- reloading/test_reloading.py | 4 ++-- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3c78623..f52f55d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Reloading [![CI](https://github.com/nneskildsf/reloading/actions/workflows/CI.yml/badge.svg)](https://github.com/nneskildsf/reloading/actions/workflows/CI.yml) +[![Checked with mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/) +[![Linting: Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) A Python utility to reload a function or loop body from source on each iteration without losing state. diff --git a/pyproject.toml b/pyproject.toml index 1ed4521..ce55b9d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,6 +38,8 @@ development = [ "nbformat", "flake8", "pyright", + "mypy", + "ruff", "build", ] diff --git a/reloading/reloading.py b/reloading/reloading.py index 04e6f78..9dcf96f 100644 --- a/reloading/reloading.py +++ b/reloading/reloading.py @@ -66,7 +66,7 @@ def reloading(fn_or_seq_or_bool: Optional[ source before each invocation or iteration, respectively. """ if fn_or_seq_or_bool is not None: - if isinstance(fn_or_seq_or_bool, Callable): + if callable(fn_or_seq_or_bool): return _reloading_function(fn_or_seq_or_bool) elif (isinstance(fn_or_seq_or_bool, Iterable) or isinstance(fn_or_seq_or_bool, bool)): diff --git a/reloading/test_reloading.py b/reloading/test_reloading.py index 82bad46..0f5460c 100644 --- a/reloading/test_reloading.py +++ b/reloading/test_reloading.py @@ -28,8 +28,8 @@ def run_and_update_source(init_src, updated_src=None, update_after=0.5): f.flush() try: - stdout, _ = proc.communicate(timeout=2) - stdout = stdout.decode("utf-8") + stdout_bytes, _ = proc.communicate(timeout=2) + stdout = stdout_bytes.decode("utf-8") has_error = False except Exception: stdout = ""