Skip to content

Commit

Permalink
Add mypy (typing) check to pre-commit (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
myakove authored Apr 4, 2024
1 parent 405e645 commit 6a7a436
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 33 deletions.
58 changes: 33 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
default_language_version:
python: python3
python: python3

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.5.0"
hooks:
- id: check-added-large-files
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
args:
- "--allow-multiple-documents"
# https://github.com/pre-commit/pre-commit-hooks/issues/273
- "--unsafe"
- id: detect-private-key
- id: mixed-line-ending
- id: debug-statements
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md] # Do not process Markdown files.
- id: end-of-file-fixer
- id: check-ast
- id: check-builtin-literals
- id: check-docstring-first
- id: check-toml
- id: check-added-large-files
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
args:
- "--allow-multiple-documents"
# https://github.com/pre-commit/pre-commit-hooks/issues/273
- "--unsafe"
- id: detect-private-key
- id: mixed-line-ending
- id: debug-statements
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md] # Do not process Markdown files.
- id: end-of-file-fixer
- id: check-ast
- id: check-builtin-literals
- id: check-docstring-first
- id: check-toml

- repo: https://github.com/PyCQA/flake8
rev: "7.0.0"
hooks:
- id: flake8
additional_dependencies: [
"git+https://github.com/RedHatQE/flake8-plugins.git",
"flake8-mutable",
]
additional_dependencies:
[
"git+https://github.com/RedHatQE/flake8-plugins.git",
"flake8-mutable",
]

- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
Expand All @@ -56,3 +57,10 @@ repos:
rev: 37.264.0
hooks:
- id: renovate-config-validator

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
hooks:
- id: mypy
exclude: ^(tests/)
additional_dependencies: [types-all]
10 changes: 5 additions & 5 deletions pyhelper_utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from time import sleep
from functools import wraps
from logging import Logger
from typing import Any
from typing import Any, Optional


def tts(ts: Any) -> int:
Expand All @@ -22,9 +22,9 @@ def tts(ts: Any) -> int:
Returns:
int: Time in seconds
"""
try:
time_and_unit = re.match(r"(?P<time>\d+)(?P<unit>\w)", str(ts)).groupdict()
except AttributeError:
if time_and_unit_match := re.match(r"(?P<time>\d+)(?P<unit>\w)", str(ts)):
time_and_unit = time_and_unit_match.groupdict()
else:
return int(ts)

_time = int(time_and_unit["time"])
Expand All @@ -39,7 +39,7 @@ def tts(ts: Any) -> int:
return int(ts)


def ignore_exceptions(logger: Logger = None, retry: int = 0) -> Any:
def ignore_exceptions(logger: Optional[Logger] = None, retry: int = 0) -> Any:
"""
Decorator to ignore exceptions with support for retry.
Expand Down
5 changes: 3 additions & 2 deletions pyhelper_utils/notifications.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from logging import Logger
from typing import Optional
import requests
import json


def send_slack_message(
message: str,
webhook_url: str = None,
logger: Logger = None,
webhook_url: Optional[str] = None,
logger: Optional[Logger] = None,
post_timout: int = 30,
raise_on_error: bool = True,
) -> None:
Expand Down
3 changes: 2 additions & 1 deletion pyhelper_utils/shell.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import subprocess
from typing import Optional

from simple_logger.logger import get_logger

Expand All @@ -11,7 +12,7 @@ def run_command(
command: list,
verify_stderr: bool = True,
shell: bool = False,
timeout: int = None,
timeout: Optional[int] = None,
capture_output: bool = True,
check: bool = True,
hide_log_command: bool = False,
Expand Down

0 comments on commit 6a7a436

Please sign in to comment.