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 Discord

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.11.0.dev1.tar.gz (9.8 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.11.0.dev1.tar.gz.

File metadata

  • Download URL: swarmauri_evaluator_anyusage-0.11.0.dev1.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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.11.0.dev1.tar.gz
Algorithm Hash digest
SHA256 d62816c3245b25c4587a720df8e30b5585805d97ae78d6046376997bfe01d6fd
MD5 a72cf99efcee9218d2acbaa4e83d52dd
BLAKE2b-256 961c3d32e85ff7c83458d9d24333dc082e3601da93909ad48473681bb0702286

See more details on using hashes here.

File details

Details for the file swarmauri_evaluator_anyusage-0.11.0.dev1-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_evaluator_anyusage-0.11.0.dev1-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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.11.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 59574d7abdf9455dfa87a7482c98019246c5d375dea5edd060d52cbca8ac645f
MD5 e8d9ef6803b2683fe09cf14c1d7c8174
BLAKE2b-256 ca7eb83081da2d397c9f103d4839922710513a612452e8f07391873bb0a737e1

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