Skip to content

Commit fc2194a

Browse files
Fix Python 3.8 compatibility and flake8 config
- Replace list[T] with List[T] from typing for Python 3.8 - Replace tuple[T] with Tuple[T] from typing - Fix .flake8 config by removing inline comments (not supported)
1 parent 54a8b7e commit fc2194a

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

.flake8

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,4 @@ exclude =
99
*.egg-info,
1010
venv,
1111
env
12-
ignore =
13-
E203, # whitespace before ':'
14-
E501, # line too long (handled by black)
15-
W503, # line break before binary operator
12+
ignore = E203,E501,W503

src/pdf_splitter/detector.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import re
44
from pathlib import Path
5-
from typing import Optional
5+
from typing import Optional, List, Tuple
66
import fitz # PyMuPDF
77

88
from pdf_splitter.models import Chapter, DetectionResult
@@ -62,7 +62,7 @@ def detect(
6262
total_pages = len(doc)
6363
has_bookmarks = len(doc.get_toc()) > 0
6464

65-
chapters: list[Chapter] = []
65+
chapters: List[Chapter] = []
6666

6767
if strategy == "bookmarks" or (strategy == "hybrid" and has_bookmarks):
6868
chapters = self._detect_from_bookmarks(doc, bookmark_level)
@@ -109,7 +109,7 @@ def _detect_from_bookmarks(self, doc: fitz.Document, bookmark_level: int = 1) ->
109109
if not toc:
110110
return []
111111

112-
chapters: list[Chapter] = []
112+
chapters: List[Chapter] = []
113113
total_pages = len(doc)
114114

115115
# Filter for specified bookmark level
@@ -146,8 +146,8 @@ def _detect_from_heuristics(self, doc: fitz.Document) -> list[Chapter]:
146146
Returns:
147147
List of detected chapters
148148
"""
149-
chapters: list[Chapter] = []
150-
potential_chapters: list[tuple[int, str, float]] = []
149+
chapters: List[Chapter] = []
150+
potential_chapters: List[Tuple[int, str, float]] = []
151151

152152
# Analyze each page for chapter headings
153153
for page_num in range(len(doc)):

src/pdf_splitter/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Models for representing chapters and detection results."""
22

33
from dataclasses import dataclass
4-
from typing import Optional
4+
from typing import Optional, List
55

66

77
@dataclass
@@ -29,7 +29,7 @@ def __str__(self) -> str:
2929
class DetectionResult:
3030
"""Container for chapter detection results."""
3131

32-
chapters: list[Chapter]
32+
chapters: List[Chapter]
3333
strategy_used: str
3434
total_pages: int
3535
has_bookmarks: bool

src/pdf_splitter/splitter.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""PDF splitting functionality."""
22

33
from pathlib import Path
4+
from typing import List
45
import fitz # PyMuPDF
56

67
from pdf_splitter.models import Chapter
@@ -27,11 +28,11 @@ def __init__(self, output_dir: Path, filename_pattern: str = "{index:02d}_{title
2728
self.output_dir.mkdir(parents=True, exist_ok=True)
2829

2930
def split(
30-
self,
31-
pdf_path: Path,
32-
chapters: list[Chapter],
31+
self,
32+
pdf_path: Path,
33+
chapters: List[Chapter],
3334
preserve_metadata: bool = True
34-
) -> list[Path]:
35+
) -> List[Path]:
3536
"""
3637
Split a PDF file into separate files by chapters.
3738
@@ -44,7 +45,7 @@ def split(
4445
List of paths to the created PDF files
4546
"""
4647
doc = fitz.open(pdf_path)
47-
created_files: list[Path] = []
48+
created_files: List[Path] = []
4849

4950
# Get original metadata
5051
metadata = doc.metadata if preserve_metadata else {}

0 commit comments

Comments
 (0)