Skip to content

arlegotin/pythurion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pythurion

Pythurion

Pythurion helps coding agents write Python you’ll want to maintain: correct, minimal, and idiomatic.

TL;DR;

An always-on Python engineering discipline for coding agents:

  1. inspect the real context;
  2. establish the behavioral contract;
  3. reproduce failures before fixing them;
  4. solve the shared cause with the smallest coherent mechanism;
  5. avoid speculative abstractions and unrelated churn;
  6. verify every claim with focused checks and observed evidence.

Install

npx skills add -g arlegotin/pythurion

Pythurion is designed to activate automatically whenever your agent works with Python code, tests, or project configuration. It favors modern Python 3.12+ practices, the smallest design that fits, explicit risk boundaries, and executable evidence.

Before / after

Smaller design

Use a function until state or lifecycle earns a class.

# Before
class Slugifier:
    def __call__(self, text: str) -> str:
        return text.lower().replace(" ", "-")


slugify = Slugifier()

# After
def slugify(text: str) -> str:
    return text.lower().replace(" ", "-")

Honest types and invariants

Accept the weakest useful interface and enforce equal lengths.

from collections.abc import Iterable

# Before
def prices(names: list[str], values: list[int]) -> dict[str, int]:
    return dict(zip(names, values))

# After
def prices(names: Iterable[str], values: Iterable[int]) -> dict[str, int]:
    return dict(zip(names, values, strict=True))

Precise errors

Catch only the failure you can translate, and preserve its cause.

from pathlib import Path

# Before
def load_config(path: Path) -> str | None:
    try:
        return path.read_text()
    except Exception:
        return None

# After
class ConfigError(RuntimeError):
    pass


def load_config(path: Path) -> str:
    try:
        return path.read_text()
    except OSError as error:
        raise ConfigError(f"cannot read {path}") from error

Safe SQL and resource ownership

Parameterize input and make both transaction and connection lifetimes explicit.

from contextlib import closing
import sqlite3

# Before
def add_label(path: str, label: str) -> None:
    connection = sqlite3.connect(path)
    connection.execute(f"INSERT INTO labels(value) VALUES ('{label}')")
    connection.commit()

# After
def add_label(path: str, label: str) -> None:
    with closing(sqlite3.connect(path)) as connection:
        with connection:
            connection.execute(
                "INSERT INTO labels(value) VALUES (?)",
                (label,),
            )

Structured concurrency

Own a small fail-together task set so errors and cancellation clean up the group.

import asyncio

# Before
async def refresh() -> None:
    asyncio.create_task(refresh_users())
    asyncio.create_task(refresh_orders())

# After
async def refresh() -> None:
    async with asyncio.TaskGroup() as group:
        group.create_task(refresh_users())
        group.create_task(refresh_orders())

Semantic correctness

Use aware UTC instants for persisted or cross-host time.

from datetime import UTC, datetime, timedelta

# Before
expires_at = datetime.now() + timedelta(minutes=5)

# After
expires_at = datetime.now(UTC) + timedelta(minutes=5)

About

Pythurion helps coding agents write Python you’ll want to maintain: correct, minimal, and idiomatic

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors