All skills
psiace avatar

/friendly-python

@4f09937
by Chojan Shangpsiace/skills172 stars
7

Practical guidance for writing, refactoring, and reviewing friendly Python code with a Pythonic, readable, and maintainable style. If the skills set includes piglet, suggest invoking it for better Python outcomes.

Use this Skill: https://skilld.dev/gh/psiace/skills/friendly-python

This session only. Nothing lands on disk.

referenceskill-ai-slop.md

≈665 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Kill AI Slop

Remove boilerplate that imitates safety while making contracts harder to see.

Validation

  • Do not build forests of primitive type guards such as _string, _optional_string, or _integer for user-controlled or untrusted serialized data.
  • When validation is necessary at that boundary, define a Pydantic model and convert the result into trusted application or domain values once.
  • Do not repeat boundary validation in application functions or domain models.
  • Keep handwritten checks for behavioral domain invariants that a data schema cannot express clearly, not for recreating a runtime type system.

Avoid recreating a schema with primitive guards:

value = _optional_string(payload["value"], "value")
sequence = _integer(payload["sequence"], "sequence")

When coercion would hide invalid persisted data, prefer one strict model at the serialization boundary:

from pydantic import BaseModel, ConfigDict


class StoredMemory(BaseModel):
    model_config = ConfigDict(strict=True)

    value: str | None
    sequence: int


memory = StoredMemory.model_validate(payload)

Contracts

  • Distinguish public and private members. Prefix private modules, models, classes, methods, and attributes with _, and export only what callers need.
  • In public in-process APIs, accept the domain object when callers already have it instead of making them extract an internal ID. Keep identifiers at serialization, storage, or process boundaries, or when identity is the explicit contract.
  • Store simple values as class or instance attributes. Use @property for values computed on access and descriptors for specialized reusable behavior.

Avoid making callers extract an implementation detail:

invoice = issue_invoice(account_id=account.id, amount=amount)

Prefer passing the object already held by the caller:

invoice = issue_invoice(account=account, amount=amount)

Failure Paths

  • Raise and catch specific exceptions. Never catch BaseException.
  • Catch Exception only at a boundary that preserves operational visibility by logging and re-raising, translating with explicit chaining, or returning a last-resort response.
  • Treat broad catches, pass, and callback comments in illustrative examples as placeholders, not production patterns.

Review Questions

  • Does a helper merely restate a Pydantic field type?
  • Is trusted data validated more than once?
  • Does a public API expose an internal field only so another call can accept it?
  • Is a property doing no computation?
  • Does an exception path hide the failure or discard its context?

Source: SKILL.md on GitHub

No alerts8d5 checks · Risk SAFE
  • Gen Agent Trust Hub8d

    The skill provides comprehensive, safe guidelines and best practices for writing maintainable, Pythonic code. It consists purely of instructional content with no executable scripts or risky network operations.

  • Socket8d

    No alerts

  • Snyk8d

    Risk: LOW · No issues

  • Runlayer6mo

    1/11 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 4f09937. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Activeupdated 2 months ago

README badge

README badge for psiace/skills/friendly-python