An evaluator component that detects and penalizes usage of the `Any` type in Python code
Project description
Swarmauri Evaluator AnyUsage
Evaluator that detects and penalizes usage of the typing.Any type in Python source files.
Features
- Recursively scans every
.pyfile underprogram.path, falling back to the current working directory when that attribute is missing. - Uses the Python AST to capture imports and annotations plus a regex pass to backfill edge cases (e.g., syntax errors).
- Deducts
penalty_per_occurrence(default0.1) for each finding and caps the deduction atmax_penalty(default1.0), yielding a normalized score between0.0and1.0where higher is better. - Returns rich metadata that lists the number of files analyzed, the total
Anyoccurrences, and per-file line numbers and snippets to accelerate remediation.
Installation
Choose the tool that best fits your workflow:
# pip
pip install swarmauri_evaluator_anyusage
# Poetry
poetry add swarmauri_evaluator_anyusage
# uv
uv add swarmauri_evaluator_anyusage
Usage
from pathlib import Path
from swarmauri_base.programs.ProgramBase import ProgramBase
from swarmauri_evaluator_anyusage import AnyTypeUsageEvaluator
workspace = Path("path/to/project")
program = ProgramBase()
program.name = workspace.name
program.path = str(workspace) # AnyTypeUsageEvaluator walks this directory on disk
evaluator = AnyTypeUsageEvaluator(penalty_per_occurrence=0.1, max_penalty=1.0)
score, metadata = evaluator.evaluate(program)
print(f"Score: {score:.2f}")
print("Files analyzed:", metadata["files_analyzed"])
print("Any usages:", metadata["total_any_occurrences"])
for report in metadata["detailed_occurrences"]:
print("-", report["file"])
for occurrence in report["occurrences"]:
print(f" line {occurrence['line']}: {occurrence['context']}")
# If you already depend on `swarmauri_standard`, import
# `from swarmauri_standard.programs.Program import Program` and replace the
# ProgramBase construction above with `Program.from_workspace(workspace)`
# before setting `program.path` to keep the on-disk directory in sync with
# your Program content.
Metadata reference
The evaluation metadata contains:
files_analyzed: Number of Python files inspected.total_any_occurrences: Count of detectedAnyusages across all files.penalty_applied: The aggregate deduction applied to the score.detailed_occurrences: A list with one entry per file containing the absolute path and the line/context pairs for each finding. Multiple entries can share a line number when both the parameter and return annotations useAny; thecontextvalue explains the exact usage (import, parameter annotation, return annotation, etc.).execution_time: Added byEvaluatorBaseto show how long the evaluation took.
Use these fields to build dashboards, enforce quality gates, or guide manual reviews.
Want to help?
If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swarmauri_evaluator_anyusage-0.4.0.dev3.tar.gz.
File metadata
- Download URL: swarmauri_evaluator_anyusage-0.4.0.dev3.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f0539f24c7014d7bb1b72347a4fc8b0b3a2cd7d320731b6e305c90c2795115c
|
|
| MD5 |
82ee5319c3e79e9853d8b6f885bdac27
|
|
| BLAKE2b-256 |
b229505dbcd092ddedc6f697d7b01e5e123f113473e196146801575a243a38ed
|
File details
Details for the file swarmauri_evaluator_anyusage-0.4.0.dev3-py3-none-any.whl.
File metadata
- Download URL: swarmauri_evaluator_anyusage-0.4.0.dev3-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3776db21584f89ba7678072ea8fcdf3d7cd1b9ed6d0facc78d6fb3163072228e
|
|
| MD5 |
7d40facde3564f0c50e164b78c777f96
|
|
| BLAKE2b-256 |
5199e7a7738f24f26cb5e88cd8b877aed515966305d202e78f3ac9400b311c60
|