pyo3-ownership-errors
Skill4 starsChanged 2 months agoApache-2.0View on GitHub
Use for PyO3 Python/Rust conversions, object lifetime, pyclass borrows, callbacks, exception mapping, and signature/stub consistency. For ABI packaging or async runtime teardown use the corresponding specialist.
In this repository81 other files it gives its agents.
- agent-cli-designSkill
- agent-tool-boundariesSkill
- behavior-first-implementationSkill
- bounded-prototypeSkill
- bounded-pr-sliceSkill
- building-fdd-validationSkill
- context-efficiencySkill
- cross-language-contractsSkill
- cross-platform-agent-instructionsSkill
- design-interviewSkill
- diagnosis-loopSkill
- domain-languageSkill
- edge-cloud-syncSkill
- handoff-continuitySkill
- immutable-pr-reviewSkill
- memory-context-hygieneSkill
- module-designSkill
- orchestrateSkill
- owner-decision-gateSkill
- parallel-portfolioSkill
- pr-gate-loopSkill
- pyo3-async-lifecycleSkill
- pyo3-buffer-performanceSkill
- pyo3-free-threadingSkill
- pyo3-wheel-releaseSkill
- python-api-typingSkill
- python-async-concurrencySkill
- python-ci-releaseSkill
- python-data-boundariesSkill
- python-packaging-environmentsSkill
- python-performanceSkill
- python-pytestSkill
- python-reviewSkill
- python-test-designSkill
- python-threading-workersSkill
- python-workflowSkill
- react-components-stateSkill
- react-performanceSkill
- repository-groundingSkill
- rust-api-designSkill
- rust-async-concurrencySkill
- rust-build-diagnosticsSkill
- rust-ci-releaseSkill
- rust-memory-layoutSkill
- rust-nextestSkill
- rust-numerics-simdSkill
- rust-performanceSkill
- rust-protocol-codecsSkill
- rust-python-bindingsSkill
- rust-reviewSkill
- rust-storage-durabilitySkill
- rust-test-designSkill
- rust-unsafe-ffiSkill
- rust-workflowSkill
- rust-workspace-dependenciesSkill
- shadcn-react-componentsSkill
- shadcn-svelte-componentsSkill
- simplify-existing-codeSkill
- source-verificationSkill
- svelte-components-runesSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 9
Start from the actual PyO3 version, Python floor, generated module layout, and Rust crate policy.
- Distinctive: line 27
Run relevant core tests plus installed Python consumer tests.
- Distinctive: line 31
Read boundary checks for examples and source links.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
PyO3 Ownership and Errors
Start from the actual PyO3 version, Python floor, generated module layout, and Rust crate policy. Keep Python-independent logic in the Rust core and Python conversion/exception policy in the binding. Do not weaken safe-core lints just because PyO3 macros need a separate boundary crate.
Map each crossing
For each changed argument, result, callback, or stored object, name the owner, borrow duration, mutability, thread/interpreter affinity, and error behavior. Bound<'py, T> is tied to an interpreter attachment lifetime; Py<T> owns a Python reference but does not make the object immutable, interpreter-independent, or safe to use without attachment. Do not extend lifetimes, store borrowed pointers in workers, or add unsafe Send/Sync to silence compiler constraints.
Convert or retain owned inputs before detaching or moving work into an async task. A safe owned copy is often the right boundary; eliminate it only with a proven lifetime and synchronization model plus performance evidence. Drop pyclass borrow guards before reentrant Python callbacks. Rust locks and Python attachment are separate resources with a lock order; avoid calling user code while holding a core lock.
A frozen pyclass can simplify ordinary field mutation but is not a blanket proof for interior mutability, native handles, caches, or callbacks. An unsendable class is an explicit thread-affinity contract, not an automatic fix for sharing. Keep extension module and interpreter lifetime in mind for globals and caches; use the version's interpreter-aware initialization facilities when warranted.
Preserve Python behavior
Choose explicit signatures/defaults and meaningful exceptions. Distinguish bad Python types, out-of-range values, invalid protocol data, transport failures, cancellation, and internal defects. Preserve native error context and public exception inheritance. Do not flatten every error into RuntimeError or turn a Rust panic into normal domain control flow. Panic handling does not make undefined behavior recoverable.
Test numeric narrowing, bool/int, missing/None, nested conversion, Unicode, and domain-specific sentinels. Conversion methods may execute Python and reenter the extension. Match .pyi files to runtime imports, classes, positional/keyword arguments, defaults, awaitables, context managers, and exceptions. Prefer real consumer tests when native signature introspection is incomplete.
Validate at both sides
Run relevant core tests plus installed Python consumer tests. Include repeated object creation/destruction, callback exceptions/reentry, invalid conversions, and explicit close. For resource-owning objects, verify ownership after owner deletion and avoid relying on garbage collection timing for correctness.
Report ownership decisions, failure contracts, tested Python surface, and unresolved lifetime or interpreter assumptions. Ask for policy guidance when supporting subinterpreters or changing public coercion rules would broaden the product.
Read boundary checks for examples and source links.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

