Skip to content

Commit

Permalink
add type hints to decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
pbelskiy committed Dec 2, 2023
1 parent 62c32d1 commit bbdc525
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions helixswarm/helpers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import re

from functools import wraps
from typing import Callable

from .exceptions import SwarmCompatibleError, SwarmError


def minimal_version(version):
def wrapper(f):
def minimal_version(version: int):
def wrapper(f: Callable):
@wraps(f)
def _check_version(self, *args, **kwargs):
if hasattr(self, 'swarm'):
Expand All @@ -18,10 +19,7 @@ def _check_version(self, *args, **kwargs):
return f(self, *args, **kwargs)

raise SwarmCompatibleError(
'Unsupported with API v{} (needed v{}+)'.format(
current_version,
version
)
f'Unsupported with API v{current_version} (needed v{version}+)'
)

return _check_version
Expand All @@ -31,6 +29,6 @@ def _check_version(self, *args, **kwargs):
def get_review_id(review_url: str) -> int:
ret = re.compile(r'/(\d+)').findall(review_url)
if not ret:
raise SwarmError('Invalid review: ' + review_url)
raise SwarmError(f'Invalid review: {review_url}')

return int(ret[0])

0 comments on commit bbdc525

Please sign in to comment.