Skip to content

Commit

Permalink
Fully type hint the OPDS Importer and OPDS2 Importer classes (PP-313) (
Browse files Browse the repository at this point in the history
…#1397)

* Add type hinting to OPDS importer class
* Type hint ODL importer classes
* Add type hints for opds for distributors
  • Loading branch information
jonathangreen authored Oct 2, 2023
1 parent 9017c23 commit 6cee785
Show file tree
Hide file tree
Showing 27 changed files with 740 additions and 396 deletions.
2 changes: 1 addition & 1 deletion api/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def _count_activity():
)

# Run the tests defined by HasCollectionSelfTests
for result in super()._run_self_tests():
for result in super()._run_self_tests(_db):
yield result

def refresh_bearer_token(self):
Expand Down
6 changes: 2 additions & 4 deletions api/circulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def __init__(
identifier_type: Optional[str],
identifier: Optional[str],
start_date: Optional[datetime.datetime],
end_date: datetime.datetime,
end_date: Optional[datetime.datetime],
fulfillment_info: Optional[FulfillmentInfo] = None,
external_identifier: Optional[str] = None,
locked_to: Optional[DeliveryMechanismInfo] = None,
Expand Down Expand Up @@ -752,9 +752,7 @@ def release_hold(self, patron: Patron, pin: str, licensepool: LicensePool) -> No
...

@abstractmethod
def update_availability(
self, licensepool: LicensePool
) -> Tuple[LicensePool, bool, bool]:
def update_availability(self, licensepool: LicensePool) -> None:
"""Update availability information for a book."""
...

Expand Down
13 changes: 6 additions & 7 deletions api/lcp/hash.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import hashlib
from abc import ABCMeta, abstractmethod
from abc import ABC, abstractmethod
from enum import Enum

from core.exceptions import BaseError
Expand All @@ -14,20 +14,19 @@ class HashingError(BaseError):
"""Raised in the case of errors occurred during hashing"""


class Hasher(metaclass=ABCMeta):
class Hasher(ABC):
"""Base class for all implementations of different hashing algorithms"""

def __init__(self, hashing_algorithm):
def __init__(self, hashing_algorithm: HashingAlgorithm) -> None:
"""Initializes a new instance of Hasher class
:param hashing_algorithm: Hashing algorithm
:type hashing_algorithm: HashingAlgorithm
"""
self._hashing_algorithm = hashing_algorithm

@abstractmethod
def hash(self, value):
raise NotImplementedError()
def hash(self, value: str) -> str:
...


class UniversalHasher(Hasher):
Expand All @@ -49,5 +48,5 @@ def hash(self, value: str) -> str:


class HasherFactory:
def create(self, hashing_algorithm):
def create(self, hashing_algorithm: HashingAlgorithm) -> Hasher:
return UniversalHasher(hashing_algorithm)
Loading

0 comments on commit 6cee785

Please sign in to comment.