Skip to content

Commit

Permalink
❇️ Add hooks to MelusineRegex
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoPerrier committed Oct 4, 2024
1 parent 223ff6b commit e1d0ca8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions melusine/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import logging
import re
from abc import ABC, abstractmethod
from typing import Any, Callable, Dict, Iterable, TypeVar, Union
from typing import Any, Callable, Dict, Iterable, List, TypeVar, Union

import pandas as pd
from sklearn.base import BaseEstimator, TransformerMixin
Expand Down Expand Up @@ -308,7 +308,7 @@ class MissingFieldError(Exception):
"""


MatchData = dict[str, list[dict[str, Any]]]
MatchData = Dict[str, List[Dict[str, Any]]]


class MelusineRegex(ABC):
Expand Down Expand Up @@ -530,7 +530,7 @@ def describe(self, text: str, position: bool = False) -> None:
position: If True, print regex match start and stop positions.
"""

def _describe_match_field(match_field_data: dict[str, list[dict[str, Any]]]) -> None:
def _describe_match_field(match_field_data: Dict[str, List[Dict[str, Any]]]) -> None:
"""
Format and print result description text.
Expand Down Expand Up @@ -609,7 +609,7 @@ def pre_match_hook(self, text: str) -> str:
"""
return text

def post_match_hook(self, match_dict: dict[str, Any]) -> dict[str, Any]:
def post_match_hook(self, match_dict: Dict[str, Any]) -> Dict[str, Any]:
"""
Hook to run after the Melusine regex match.
Expand Down
4 changes: 2 additions & 2 deletions tests/base/test_melusine_regex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, List, Optional, Union, Any
from typing import Any, Dict, List, Optional, Union

import pytest

Expand Down Expand Up @@ -169,7 +169,7 @@ def test_pre_match_hook():

class PostMatchHookVirusRegex(VirusRegex):

def post_match_hook(self, match_dict: dict[str, Any]) -> dict[str, Any]:
def post_match_hook(self, match_dict: Dict[str, Any]) -> Dict[str, Any]:
"""Test custom post processing of match data"""
if match_dict[self.MATCH_RESULT] is True:
if "NEUTRAL_MEDICAL_VIRUS" in match_dict[self.NEUTRAL_MATCH_FIELD] and "NEUTRAL_INSECT" in match_dict[self.NEUTRAL_MATCH_FIELD]:
Expand Down

0 comments on commit e1d0ca8

Please sign in to comment.