6c7348023b
* chore: enable ANN ruff ruleset, exclude components and testing dirs
- Add ANN (flake8-annotations) to ruff select in pyproject.toml
- Globally ignore ANN401 (Any) for legitimate dynamic types
- Exclude haystack/components/** and haystack/testing/** from ANN checks
(mirrors existing mypy disallow_incomplete_defs=false overrides)
- Fix all 43 ANN violations in the remaining modules:
- Add -> None to __post_init__ in breakpoints, file_content,
image_content, sparse_embedding, streaming_chunk, tool, toolset, auth
- Add -> str to __str__ in filter_policy, auth, hf (2x)
- Add *args: Any, **kwargs: Any + return types to metaclass __call__
in component.py and document.py, and __new__ in chat_message.py
- Add -> None to async _runner() in async_pipeline.py
- Type _check_callable_compatibility args and return bool
- Add Callable return type to _dispatch_bm25
- Type send_telemetry decorator params and return
- Type __init_track__ and __setattr_warn__ wrapper functions
- Type _parse_date, _parse_generic_args, async run()
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* chore: fix ANN violations in .github/utils and docs-website scripts
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* chore: fix mypy errors introduced by ANN annotations
- async_pipeline.py: _runner() returns Mapping[str, Any], not None
- dataclasses.py: extend type: ignore to cover arg-type in addition to call-arg
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* alphabetical order of ruff rules
* fix: add ANN type annotations to haystack/components and remove per-file-ignore
Fix all ANN (flake8-annotations) violations in haystack/components/ so
the per-file-ignore for that directory can be removed entirely.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* chore: remove haystack.components.* from mypy disallow_incomplete_defs override
All ANN type annotations have been added to haystack/components/, so the
mypy override is no longer needed for that module.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
import ast
|
|
import hashlib
|
|
from collections.abc import Iterator
|
|
from pathlib import Path
|
|
|
|
|
|
def docstrings_checksum(python_files: Iterator[Path]) -> str:
|
|
"""
|
|
Calculate the checksum of the docstrings in the given Python files.
|
|
"""
|
|
files_content = (f.read_text() for f in python_files)
|
|
trees = (ast.parse(c) for c in files_content)
|
|
|
|
# Get all docstrings from async functions, functions,
|
|
# classes and modules definitions
|
|
docstrings = []
|
|
for tree in trees:
|
|
for node in ast.walk(tree):
|
|
if not isinstance(node, (ast.AsyncFunctionDef, ast.FunctionDef, ast.ClassDef, ast.Module)):
|
|
# Skip all node types that can't have docstrings to prevent failures
|
|
continue
|
|
docstring = ast.get_docstring(node)
|
|
if docstring:
|
|
docstrings.append(docstring)
|
|
|
|
# Sort them to be safe, since ast.walk() returns
|
|
# nodes in no specified order.
|
|
# See https://docs.python.org/3/library/ast.html#ast.walk
|
|
docstrings.sort()
|
|
|
|
return hashlib.md5(str(docstrings).encode("utf-8")).hexdigest()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import argparse
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--root", help="Haystack root folder", required=True, type=Path)
|
|
args = parser.parse_args()
|
|
|
|
# Get all Haystack and rest_api python files
|
|
root: Path = args.root.absolute()
|
|
haystack_files = root.glob("haystack/**/*.py")
|
|
|
|
md5 = docstrings_checksum(haystack_files)
|
|
print(md5)
|