chore: Fix for additional linting rules

This commit is contained in:
Marty Oehme 2025-09-11 13:38:47 +02:00
parent 96cd4929c9
commit f5455b6946
Signed by: Marty
GPG key ID: 4E535BC19C61886E
7 changed files with 58 additions and 40 deletions

View file

@ -19,9 +19,7 @@ class PdfExtractor:
if not filename.is_file():
logger.error(f"File {str(filename)} not readable.")
return False
if not self._is_pdf(filename):
return False
return True
return self._is_pdf(filename)
def run(self, filename: Path) -> list[Annotation]:
"""Extract annotations from a file.
@ -39,15 +37,15 @@ class PdfExtractor:
if not quote and not note:
continue
color: tuple[float, float, float] = cast(
tuple[float, float, float],
"tuple[float, float, float]",
(
annot.colors.get("fill")
or annot.colors.get("stroke")
or (0.0, 0.0, 0.0)
),
)
page_nr: int = cast(int, page.number or 0)
highlight_type: str = cast(str, annot.type[1] or "")
page_nr: int = cast("int", page.number or 0)
highlight_type: str = cast("str", annot.type[1] or "")
a = Annotation(
file=str(filename),
content=quote or "",
@ -83,7 +81,7 @@ class PdfExtractor:
should both be included or are the same, using
Levenshtein distance.
"""
content = cast(str, annotation.info["content"].replace("\n", " "))
content = cast("str", annotation.info["content"].replace("\n", " "))
written = page.get_textbox(annotation.rect).replace("\n", " ")
# highlight with selection in note
@ -94,13 +92,13 @@ class PdfExtractor:
if Levenshtein.ratio(content, written) > minimum_similarity:
return (content, None)
# both a highlight and a note
elif content and written:
if content and written:
return (written, content)
# an independent note, not a highlight
elif content:
if content:
return (None, content)
# highlight with selection not in note
elif written:
if written:
return (written, None)
# just a highlight without any text
return (None, None)

View file

@ -2,7 +2,6 @@
from pathlib import Path
import magic
import papis.config
import papis.logging
from bs4 import BeautifulSoup
@ -13,7 +12,7 @@ logger = papis.logging.get_logger(__name__)
class PocketBookExtractor:
def can_process(self, filename: Path) -> bool:
if not magic.from_file(filename, mime=True) == "text/xml":
if magic.from_file(filename, mime=True) != "text/xml":
return False
content = self._read_file(filename)
@ -21,11 +20,11 @@ class PocketBookExtractor:
return False
html = BeautifulSoup(content, features="xml")
if not html.find(
"meta", {"name": "generator", "content": "PocketBook Bookmarks Export"}
):
return False
return True
return bool(
html.find(
"meta", {"name": "generator", "content": "PocketBook Bookmarks Export"}
)
)
def run(self, filename: Path) -> list[Annotation]:
"""Extract annotations from pocketbook html file.
@ -78,8 +77,8 @@ class PocketBookExtractor:
def _read_file(self, filename: Path) -> str:
try:
with open(filename) as f:
return f.read()
with filename.open("r") as fr:
return fr.read()
except FileNotFoundError:
logger.error(f"Could not open file {filename} for extraction.")
return ""

View file

@ -17,7 +17,7 @@ class ReadEraExtractor:
"""
def can_process(self, filename: Path) -> bool:
if not magic.from_file(filename, mime=True) == "text/plain":
if magic.from_file(filename, mime=True) != "text/plain":
return False
content = self._read_file(filename)
@ -83,8 +83,8 @@ class ReadEraExtractor:
def _read_file(self, filename: Path) -> list[str]:
try:
with open(filename, encoding="utf-8") as f:
return f.readlines()
with filename.open("r") as fr:
return fr.readlines()
except FileNotFoundError:
logger.error(f"Could not open file {filename} for extraction.")
return []