Python coding
Skill YuanshengClaw/yuansheng-kit/.agents/skills/python-coding
Agent-oriented toolkit for RISC-V optimization knowledge extraction, pattern mining, real-hardware performance analysis, root-cause diagnosis, and code generation
npx -y skills add YuanshengClaw/yuansheng-kit --skill python-codingAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
3 things to look at
- 16 days oldThe repository was created 16 days ago. New is not bad, but a brand new repository carrying a familiar-sounding name is the shape a typosquat arrives in, and there has been no time for anyone else to find a problem with it.
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 3 stars3 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Python coding standards, idioms, and review guidance for writing, reviewing, refactoring, and organizing Python code. Use when working on Python modules, functions, tests, package layout, type hints, error handling, context managers, generators, dataclasses, decorators, concurrency patterns, performance improvements, or Python anti-pattern cleanup.
SKILL.md
4.1 KB, as published. Nobody here has run it
Python Coding
Use this skill to produce Python code that is readable, explicit, typed where useful, and consistent with the surrounding project.
Required Workflow
- Inspect nearby Python code and project configuration before editing. Local conventions, supported Python versions, and established test patterns override generic guidance.
- If the task configures Python project tooling, dependencies, package
metadata, linting, type checking, testing, or migration behavior, also use
the applicable project setup skill, such as
modern-pythonwhen available. This skill is for Python code quality and idioms, not for owning dependency policy. - Read
references/python-coding-guide.mdwhen concrete examples or detailed idiom guidance would help the task. - Keep edits focused on the requested Python behavior. Do not refactor broad surfaces only to apply style preferences.
- Run the narrowest useful validation for the touched code: formatter, linter, type checker, and tests as available in the project.
Coding Standards
- Prefer clear names, direct control flow, and straightforward data structures over clever or compressed code.
- Make side effects explicit. Avoid imports or helper calls that silently mutate process-wide state unless that is the established project pattern.
- Annotate public function signatures and non-obvious internal data shapes.
Prefer modern built-in generics such as
list[str]anddict[str, int]when the supported Python version allows them. - Use structural typing with
Protocolwhen behavior matters more than a concrete class. - Catch specific exceptions, preserve context with exception chaining, and avoid silent failure paths.
- Use context managers for files, locks, transactions, network sessions, and other resources with lifecycle requirements.
- Use comprehensions for simple transformations. Expand complex filtering or multi-step transformations into named functions or explicit loops.
- Use generators for lazy processing and large inputs when callers can consume iterators.
- Use
dataclassfor ordinary data containers and named tuples or frozen data classes for small immutable records. - Use decorators sparingly. Preserve wrapped function metadata with
functools.wraps. - Choose concurrency by workload: threads for blocking I/O, processes for CPU
work, and
async/awaitfor high-concurrency asynchronous I/O. - Prefer
pathlib.Pathfor filesystem paths in new code unless local APIs expect strings. - Avoid repeated string concatenation in loops. Use
"".join(...)orio.StringIOfor incremental construction.
Review Checklist
Look for these Python-specific problems when reviewing or refactoring:
- mutable default arguments;
- bare
exceptblocks or overly broad exception handling; type(x) == ...instead ofisinstance;== Noneor!= Noneinstead ofis Noneoris not None;- wildcard imports;
- manual resource cleanup where a context manager is available;
- complex comprehensions that hide branching or error handling;
- accidental eager list materialization for large data;
- untyped public APIs where types would clarify contracts;
- logging, error messages, or exception types that obscure failure causes;
- global mutable state introduced without a clear lifecycle.
Reference
The detailed source guide is bundled at references/python-coding-guide.md.
Load it for concrete examples covering:
- Python readability principles and EAFP style;
- type hints, aliases, generics, and protocols;
- error handling and custom exception hierarchies;
- context managers;
- comprehensions and generators;
- dataclasses, named tuples, and decorators;
- threading, multiprocessing, and async I/O;
- package organization and imports;
- memory, performance, tooling, and anti-patterns.