CodeSampleX

Sample

greenlet 3.5.4: greenlet.parent

Verified sample for pypi greenlet 3.5.4: greenlet.parent. The contract ran on python 3.12 · linux alpine/x64 · docker and passed: assert greenlet.greenlet…

sha256:3cd72ec2230ef46dee673e23871388b26db13461dc4455c9b9c6dd1a3634da3d

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment python 3.12 linux 24 · alpine · musl x64 python 3.12 python pip 24

Verification-run environments

Environment Contract Stages Run
python 3.12 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · python@1python:3.12-alpine@sha256:d09d15e60962…
2026-09-01

Case

HOW
Goal
verify greenlet.greenlet.parent in pkg:pypi/greenlet@3.5.4
Packages
Symbols
  • greenlet.greenlet.parent
Environment
python 3.12
Created
2026-09-01T12:13:59Z

Contract

  1. assert greenlet.greenlet default parent is the creating greenlet from greenlet.getcurrent()
  2. assert greenlet.greenlet accepts explicit parent argument in constructor and returns to specified parent on completion
  3. assert greenlet.greenlet.parent attribute is mutable and redirects completion control flow to new parent
  4. assert main greenlet parent is None and modifying main greenlet parent raises AttributeError or ValueError
  5. assert setting cyclic greenlet parent hierarchy raises ValueError
  6. assert setting non-greenlet or None parent raises TypeError or ValueError
  7. assert uncaught exceptions in child greenlet propagate to its parent greenlet

Files

  • PROMPT.md
  • csx.json
  • pyproject.toml
  • requirements.txt
  • spec.json
  • test/contract.py

Download the source artifact (tar.gz)

Source

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify greenlet.greenlet.parent in pkg:pypi/greenlet@3.5.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:pypi/greenlet@3.5.4
Demonstrate these symbols/APIs:
  - greenlet.greenlet.parent
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:0e8c6060db78a3dd2d9110228861758997e7370c7d808e238593d96935488e18","constraints":{"executionContext":"python"},"contract":["assert greenlet.greenlet default parent is the creating greenlet from greenlet.getcurrent()","assert greenlet.greenlet accepts explicit parent argument in constructor and returns to specified parent on completion","assert greenlet.greenlet.parent attribute is mutable and redirects completion control flow to new parent","assert main greenlet parent is None and modifying main greenlet parent raises AttributeError or ValueError","assert setting cyclic greenlet parent hierarchy raises ValueError","assert setting non-greenlet or None parent raises TypeError or ValueError","assert uncaught exceptions in child greenlet propagate to its parent greenlet"],"goal":"verify greenlet.greenlet.parent in pkg:pypi/greenlet@3.5.4","kind":"HOW","packages":["pkg:pypi/greenlet@3.5.4"],"schemaVersion":1,"symbols":["greenlet.greenlet.parent"]},"contractCommand":["python3","test/contract.py"],"environment":{"arch":"x64","distro":"alpine","ecosystem":"pypi","executionContext":"python","language":"python","libc":"musl","moduleSystem":"standard","os":"linux","osVersionBucket":"24","packageManager":"pip","packageManagerVersion":"24.0","runtime":"python","runtimeVersion":"3.12","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/greenlet@3.5.4"],"schemaVersion":1,"subject":"pkg:pypi/greenlet@3.5.4","symbols":["greenlet.greenlet.parent"],"verifierAdapter":"python@1"}
pyproject.toml
[project]
name = "verify-greenlet-parent"
version = "0.1.0"
dependencies = [
    "greenlet==3.5.4",
]
requirements.txt
greenlet==3.5.4
spec.json
{
  "schemaVersion": 1,
  "goal": "verify greenlet.greenlet.parent in pkg:pypi/greenlet@3.5.4",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/greenlet@3.5.4"
  ],
  "symbols": [
    "greenlet.greenlet.parent"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.py
import greenlet


def test_default_parent_is_current():
    current = greenlet.getcurrent()

    def worker():
        return 42

    g = greenlet.greenlet(worker)
    assert g.parent is current
    res = g.switch()
    assert res == 42
    assert g.dead is True


def test_explicit_parent_constructor():
    events = []

    def p_func(*args):
        events.append("p_start")
        c_res = child.switch()
        events.append(f"p_end:{c_res}")
        return "p_done"

    def c_func():
        events.append("c_run")
        return "c_done"

    parent_g = greenlet.greenlet(p_func)
    child = greenlet.greenlet(c_func, parent=parent_g)
    assert child.parent is parent_g

    val = parent_g.switch()
    assert val == "p_done"
    assert events == ["p_start", "c_run", "p_end:c_done"]
    assert child.dead is True
    assert parent_g.dead is True


def test_reassign_parent_redirects_control():
    events = []

    def worker():
        events.append("worker_done")
        return "from_worker"

    def alt_parent(arg=None):
        events.append(f"alt_received:{arg}")
        return "alt_done"

    g = greenlet.greenlet(worker)
    alt_g = greenlet.greenlet(alt_parent)

    g.parent = alt_g
    assert g.parent is alt_g

    res = g.switch()
    assert res == "alt_done"
    assert events == ["worker_done", "alt_received:from_worker"]
    assert g.dead is True
    assert alt_g.dead is True


def test_main_greenlet_parent_is_none_and_immutable():
    main = greenlet.getcurrent()
    assert main.parent is None

    g = greenlet.greenlet(lambda: None)
    try:
        main.parent = g
        assert False, "Should have raised AttributeError/ValueError when setting parent of main greenlet"
    except (AttributeError, ValueError) as exc:
        assert isinstance(exc, (AttributeError, ValueError))


def test_cyclic_parent_raises_value_error():
    g1 = greenlet.greenlet(lambda: None)
    g2 = greenlet.greenlet(lambda: None)

    try:
        g1.parent = g1
        assert False, "Should have raised ValueError for self-referential parent"
    except ValueError as exc:
        assert isinstance(exc, ValueError)

    g2.parent = g1
    try:
        g1.parent = g2
        assert False, "Should have raised ValueError for cyclic parent chain"
    except ValueError as exc:
        assert isinstance(exc, ValueError)


def test_invalid_parent_type_raises_type_error():
    g = greenlet.greenlet(lambda: None)

    try:
        g.parent = "not_a_greenlet"
        assert False, "Should have raised TypeError for non-greenlet parent"
    except TypeError as exc:
        assert isinstance(exc, TypeError)

    try:
        g.parent = None
        assert False, "Should have raised TypeError/ValueError for None parent"
    except (TypeError, ValueError) as exc:
        assert isinstance(exc, (TypeError, ValueError))


def test_exception_propagates_to_parent():
    events = []

    class CustomError(Exception):
        pass

    def faulty_child():
        events.append("child_raising")
        raise CustomError("boom")

    child = greenlet.greenlet(faulty_child)
    assert child.parent is greenlet.getcurrent()

    try:
        child.switch()
        assert False, "Exception should have propagated to parent"
    except CustomError as exc:
        events.append("parent_caught")
        assert str(exc) == "boom"

    assert events == ["child_raising", "parent_caught"]
    assert child.dead is True


def main():
    test_default_parent_is_current()
    test_explicit_parent_constructor()
    test_reassign_parent_redirects_control()
    test_main_greenlet_parent_is_none_and_immutable()
    test_cyclic_parent_raises_value_error()
    test_invalid_parent_type_raises_type_error()
    test_exception_propagates_to_parent()
    print("All greenlet.greenlet.parent contract assertions passed.")


if __name__ == "__main__":
    main()

Origin Seeder

anonymous