Skip to main content

An evaluator component that detects and penalizes usage of the `Any` type in Python code

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_evaluator_anyusage


Swarmauri Evaluator AnyUsage

Evaluator that detects and penalizes usage of the typing.Any type in Python source files.

Features

  • Recursively scans every .py file under program.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 (default 0.1) for each finding and caps the deduction at max_penalty (default 1.0), yielding a normalized score between 0.0 and 1.0 where higher is better.
  • Returns rich metadata that lists the number of files analyzed, the total Any occurrences, 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 detected Any usages 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 use Any; the context value explains the exact usage (import, parameter annotation, return annotation, etc.).
  • execution_time: Added by EvaluatorBase to 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swarmauri_evaluator_anyusage-0.4.0.dev5.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file swarmauri_evaluator_anyusage-0.4.0.dev5.tar.gz.

File metadata

  • Download URL: swarmauri_evaluator_anyusage-0.4.0.dev5.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

Hashes for swarmauri_evaluator_anyusage-0.4.0.dev5.tar.gz
Algorithm Hash digest
SHA256 fc35bedb2685a03bdaf8d0b5020c22613bca3c8dbba62b6b145fb06da7aa1da9
MD5 c045e62d78b1894255dee2cd3158eae6
BLAKE2b-256 bc16f73847a7ef13f937892881206c6f5c2f8302fb2b82ffe89350d53eb06746

See more details on using hashes here.

File details

Details for the file swarmauri_evaluator_anyusage-0.4.0.dev5-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_evaluator_anyusage-0.4.0.dev5-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

Hashes for swarmauri_evaluator_anyusage-0.4.0.dev5-py3-none-any.whl
Algorithm Hash digest
SHA256 0d3d6fcea2cfc717479189385a2503e481705bf96c0d9280212d7b6555b1ee6e
MD5 119f1c359c21b785523d44e5c0993d93
BLAKE2b-256 1eae8807c79d686c90417489ee5c6cefeefacb018e1e7b16961713dc6518c866

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page