text-splitters: Set strict mypy rules (#30900)

* Add strict mypy rules
* Fix mypy violations
* Add error codes to all type ignores
* Add ruff rule PGH003
* Bump mypy version to 1.15
This commit is contained in:
Christophe Bornet
2025-04-23 06:41:24 +03:00
committed by GitHub
parent eedda164c6
commit 8c5ae108dd
9 changed files with 81 additions and 77 deletions

View File

@@ -404,18 +404,18 @@ class ExperimentalMarkdownSyntaxTextSplitter:
self.current_chunk = Document(page_content="")
# Match methods
def _match_header(self, line: str) -> Union[re.Match, None]:
def _match_header(self, line: str) -> Union[re.Match[str], None]:
match = re.match(r"^(#{1,6}) (.*)", line)
# Only matches on the configured headers
if match and match.group(1) in self.splittable_headers:
return match
return None
def _match_code(self, line: str) -> Union[re.Match, None]:
def _match_code(self, line: str) -> Union[re.Match[str], None]:
matches = [re.match(rule, line) for rule in [r"^```(.*)", r"^~~~(.*)"]]
return next((match for match in matches if match), None)
def _match_horz(self, line: str) -> Union[re.Match, None]:
def _match_horz(self, line: str) -> Union[re.Match[str], None]:
matches = [
re.match(rule, line) for rule in [r"^\*\*\*+\n", r"^---+\n", r"^___+\n"]
]