From b16b405d50f0c8d9dd5244b756737ffc926838ba Mon Sep 17 00:00:00 2001 From: Benjamin Gilbert Date: Fri, 1 Mar 2024 17:48:32 +0900 Subject: [PATCH] pre-commit: require PEP 563 type annotations Require `from __future__ import annotations` in every Python file that isn't a known config file. Prep for adding type annotations. Signed-off-by: Benjamin Gilbert --- .pre-commit-config.yaml | 15 +++++++++++++++ doc/jekyll_fix.py | 2 ++ examples/deepzoom/deepzoom_multiserver.py | 2 ++ examples/deepzoom/deepzoom_server.py | 2 ++ examples/deepzoom/deepzoom_tile.py | 2 ++ openslide/__init__.py | 2 ++ openslide/deepzoom.py | 2 ++ openslide/lowlevel.py | 2 ++ tests/common.py | 2 ++ tests/test_base.py | 8 +++++++- tests/test_deepzoom.py | 2 ++ tests/test_imageslide.py | 2 ++ tests/test_openslide.py | 2 ++ 13 files changed, 44 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9df26d73..5ad401b5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -64,3 +64,18 @@ repos: hooks: - id: check-hooks-apply - id: check-useless-excludes + + - repo: local + hooks: + - id: annotations + name: Require "from __future__ import annotations" + language: pygrep + types: [python] + # exclude config-like files + exclude: "^(setup\\.py|doc/conf\\.py|openslide/_version\\.py)$" + # Allow files with import statement, or of less than two characters. + # One-character files are allowed because that's the best we can do + # with paired negative lookbehind and lookahead assertions. ^ and $ + # don't work because --multiline causes them to match at newlines. + entry: "(?