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.dev34.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.dev34.tar.gz.

File metadata

  • Download URL: swarmauri_evaluator_anyusage-0.3.0.dev34.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.dev34.tar.gz
Algorithm Hash digest
SHA256 c6de380677ae66f8b490771add79abe65938d1a4dd371d581806f9c4b93c9f85
MD5 73b18d739e4c3dca9f2d3ed67eadb3a1
BLAKE2b-256 89bac54e18c305f16077c3cae5af5ceb1bcc81977997b850367d4588876fcba3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swarmauri_evaluator_anyusage-0.3.0.dev34-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.dev34-py3-none-any.whl
Algorithm Hash digest
SHA256 836cd0f972a3df224ddcea04ecc9cfaf51f316b588c205c2f36746366b2f5518
MD5 2fc23431f7a06203cc50db0ede6927cb
BLAKE2b-256 4b39c74e0382eae7a14ed2429365e92d7a615b6ca39e9e4f28e4c2da40cc6138

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