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.3.0.dev33.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.3.0.dev33.tar.gz.

File metadata

  • Download URL: swarmauri_evaluator_anyusage-0.3.0.dev33.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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.3.0.dev33.tar.gz
Algorithm Hash digest
SHA256 d4939fa9a68716fd22f9003873e80a1554fec97e08ee4ebff9a4ccdbe101a504
MD5 314590458b6afcaa6623d84bdd066801
BLAKE2b-256 e71d20258544ad033eed9ed5698b8f10ea90a4729537688e6bfd393f7a5ca1f3

See more details on using hashes here.

File details

Details for the file swarmauri_evaluator_anyusage-0.3.0.dev33-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_evaluator_anyusage-0.3.0.dev33-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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.3.0.dev33-py3-none-any.whl
Algorithm Hash digest
SHA256 9fa3b0f4634c099f3d94dcd61179ba98cd30968358c53a86c38240f60f7643e7
MD5 2dfe1afc7b4624b44e1c642e9c871b8b
BLAKE2b-256 5e3d831d91ab316f2d938c658e1caaed3bdb0f602e66170cbc36423a6616e4f7

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