Skip to content

Commit

Permalink
add warning if DuplicateDetector is used
Browse files Browse the repository at this point in the history
  • Loading branch information
yagebu committed Jan 3, 2025
1 parent 100bcae commit 9dae2e5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pylintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[MESSAGES CONTROL]
disable = too-few-public-methods
disable = too-few-public-methods,cyclic-import
21 changes: 18 additions & 3 deletions smart_importer/detector.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
"""Duplicate detector hook."""

from __future__ import annotations

import logging
from typing import Callable

from beangulp import similar
from beancount.core import data
from beangulp import Importer, similar

from smart_importer.hooks import ImporterHook

Expand All @@ -18,12 +22,23 @@ class DuplicateDetector(ImporterHook):
entries to classify against.
"""

def __init__(self, comparator=None, window_days=2):
def __init__(
self,
comparator: Callable[[data.Directive, data.Directive], bool]
| None = None,
window_days: int = 2,
) -> None:
super().__init__()
self.comparator = comparator
self.window_days = window_days

def __call__(self, importer, file, imported_entries, existing):
def __call__(
self,
importer: Importer,
file: str,
imported_entries: data.Directives,
existing: data.Directives,
) -> data.Directives:
"""Add duplicate metadata for imported transactions.
Args:
Expand Down
13 changes: 11 additions & 2 deletions smart_importer/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ def patched_extract_method(

return imported_entries

importer.extract = patched_extract_method
importer.deduplicate = lambda entries, existing: None
importer.extract = patched_extract_method # type: ignore

# pylint: disable=import-outside-toplevel
from smart_importer.detector import DuplicateDetector

if any(isinstance(hook, DuplicateDetector) for hook in hooks):
logger.warning(
"Use of DuplicateDetector detected - this is deprecated, "
"please use the beangulp.Importer.deduplicate method directly."
)
importer.deduplicate = lambda entries, existing: None # type: ignore
return importer

0 comments on commit 9dae2e5

Please sign in to comment.