Skip to content

Commit

Permalink
add Protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
iagocanalejas committed Oct 24, 2023
1 parent d707102 commit 31cb867
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
12 changes: 9 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: requirements-txt-fixer
Expand All @@ -13,14 +13,20 @@ repos:
- id: mixed-line-ending
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.5.0
hooks:
- id: setup-cfg-fmt

- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py311-plus]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.282
rev: v0.1.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
17 changes: 6 additions & 11 deletions rscraping/parsers/html/_parser.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
from abc import ABC, abstractmethod
from collections.abc import Generator
from typing import Any
from typing import Any, Protocol

from parsel import Selector

from rscraping.data.models import Datasource, Lineup, Race, RaceName


class HtmlParser(ABC):
class HtmlParser(Protocol):
DATASOURCE: Datasource

@abstractmethod
def parse_race(self, selector: Selector, **kwargs) -> Race | None:
raise NotImplementedError
...

@abstractmethod
def parse_race_ids(self, selector: Selector, **kwargs) -> Generator[str, Any, Any]:
raise NotImplementedError
...

@abstractmethod
def parse_race_names(self, selector: Selector, **kwargs) -> Generator[RaceName, Any, Any]:
raise NotImplementedError
...

@abstractmethod
def parse_lineup(self, selector: Selector, **kwargs) -> Lineup:
raise NotImplementedError
...
7 changes: 3 additions & 4 deletions rscraping/parsers/pdf/_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from abc import ABC, abstractmethod
from typing import Protocol

from fitz import Page

Expand All @@ -8,9 +8,8 @@
logger = logging.getLogger(__name__)


class PdfParser(ABC):
class PdfParser(Protocol):
DATASOURCE: Datasource

@abstractmethod
def parse_lineup(self, page: Page) -> Lineup:
raise NotImplementedError
...

0 comments on commit 31cb867

Please sign in to comment.