From eef3819401a930850578f8c1064ba3dbcd31de72 Mon Sep 17 00:00:00 2001 From: francisco souza <108725+fsouza@users.noreply.github.com> Date: Mon, 29 May 2023 00:34:56 -0400 Subject: [PATCH] Add pyright to pre-commit config Also configure reorder-python-imports to add annotations import everywhere. --- .pre-commit-config.yaml | 7 +++++++ test_autoflake.py | 2 ++ test_fuzz.py | 2 ++ test_fuzz_pypi.py | 13 +++++++++---- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9b995f5..705b84a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,6 +17,8 @@ repos: - id: reorder-python-imports args: - --py38-plus + - --add-import + - from __future__ import annotations - repo: https://github.com/charliermarsh/ruff-pre-commit rev: v0.0.269 @@ -46,3 +48,8 @@ repos: rev: v0.13 hooks: - id: validate-pyproject + + - repo: https://github.com/fsouza/mirrors-pyright + rev: v1.1.310 + hooks: + - id: pyright diff --git a/test_autoflake.py b/test_autoflake.py index c321dc9..507f69c 100755 --- a/test_autoflake.py +++ b/test_autoflake.py @@ -1,5 +1,7 @@ #!/usr/bin/env python """Test suite for autoflake.""" +from __future__ import annotations + import contextlib import functools import io diff --git a/test_fuzz.py b/test_fuzz.py index 3d2dd93..2668b93 100755 --- a/test_fuzz.py +++ b/test_fuzz.py @@ -5,6 +5,8 @@ done by doing a syntax check after the autoflake run. The number of Pyflakes warnings is also confirmed to always improve. """ +from __future__ import annotations + import argparse import os import shlex diff --git a/test_fuzz_pypi.py b/test_fuzz_pypi.py index 13317cc..587d116 100755 --- a/test_fuzz_pypi.py +++ b/test_fuzz_pypi.py @@ -1,10 +1,13 @@ #!/usr/bin/env python """Fuzz test against the latest packages on PyPI.""" +from __future__ import annotations + import os import subprocess import sys import tarfile import zipfile +from typing import Iterable import test_fuzz @@ -15,7 +18,7 @@ ) -def latest_packages(last_hours): +def latest_packages(last_hours: int) -> Iterable[str]: """Return names of latest released packages on PyPI.""" process = subprocess.Popen( ["yolk", f"--latest-releases={last_hours}"], @@ -27,7 +30,7 @@ def latest_packages(last_hours): yield line.split()[0] -def download_package(name, output_directory): +def download_package(name: str, output_directory: str) -> None: """Download package to output_directory. Raise CalledProcessError on failure. @@ -38,7 +41,7 @@ def download_package(name, output_directory): ) -def extract_package(path, output_directory): +def extract_package(path: str, output_directory: str) -> bool: """Extract package at path.""" if path.lower().endswith(".tar.gz"): try: @@ -60,7 +63,7 @@ def extract_package(path, output_directory): return False -def main(): +def main() -> int: """Run main.""" try: os.mkdir(TMP_DIR) @@ -138,6 +141,8 @@ def main(): file=sys.stderr, ) + return 0 + if __name__ == "__main__": try: