CodeSampleX

サンプル

uvloop 0.22.1: EventLoopPolicy, install, new_event_loop

検証済みサンプル — pypi uvloop 0.22.1: EventLoopPolicy, install, new_event_loop. python 3.12 · linux alpine/x64 · docker で contract を実行し、成功しました.

sha256:2ce47866a5864ba793f7f51ce3a1dc73d5d710e5d46be32bc3511c1870f071bf

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 python 3.12 linux 24 · ubuntu · glibc 2.39 x64 python 3.12 python pip

検証実行環境

環境 コントラクト ステージ 実行日
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-08-27

ケース

HOW
ゴール
verify pkg:pypi/uvloop@0.22.1
パッケージ
シンボル
  • uvloop.EventLoopPolicy
  • uvloop.install
  • uvloop.new_event_loop
  • uvloop.run
環境
python 3.12
作成日
2026-08-27T18:07:40Z

コントラクト

  1. uvloop.EventLoopPolicy implements asyncio.AbstractEventLoopPolicy and creates uvloop.Loop instances
  2. uvloop.install sets uvloop.EventLoopPolicy as the default asyncio event loop policy
  3. uvloop.new_event_loop returns a new unclosed uvloop.Loop instance
  4. uvloop.run executes an async coroutine to completion and returns its result
  5. uvloop.run propagates unhandled exceptions raised inside the coroutine
  6. uvloop.run raises TypeError when passed a non-coroutine object

ファイル

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

ソースアーティファクトをダウンロード (tar.gz)

ソース

NOTES.md
# uvloop: Fast asyncio Event Loop (pkg:pypi/uvloop@0.22.1)

## Prior Network Solutions

The network query for `verify pkg:pypi/uvloop@0.22.1` returned NO_SAFE_MATCH.

## Release Pinned

- `uvloop`: 0.22.1

## Observed Behaviour

In `uvloop` 0.22.1:
1. `uvloop.EventLoopPolicy()` instantiates an `asyncio.AbstractEventLoopPolicy` that creates `uvloop.Loop` instances upon calling `new_event_loop()`.
2. `uvloop.install()` installs `uvloop.EventLoopPolicy` as the default event loop policy via `asyncio.set_event_loop_policy()`.
3. `uvloop.new_event_loop()` returns a fresh, unclosed `uvloop.Loop` instance that can execute async coroutines via `run_until_complete()`.
4. `uvloop.run(coro)` creates a new uvloop event loop, runs the coroutine to completion, and returns its result.
5. `uvloop.run(coro)` propagates exceptions raised within the coroutine.
6. `uvloop.run(obj)` raises `TypeError` if passed a non-coroutine object.
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 pkg:pypi/uvloop@0.22.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:pypi/uvloop@0.22.1
Demonstrate these symbols/APIs:
  - uvloop.EventLoopPolicy
  - uvloop.install
  - uvloop.new_event_loop
  - uvloop.run

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:bbe1bad0eb43decaee81946c826973f51356cecd553ac7897cf147915e566dd2","contract":["uvloop.EventLoopPolicy implements asyncio.AbstractEventLoopPolicy and creates uvloop.Loop instances","uvloop.install sets uvloop.EventLoopPolicy as the default asyncio event loop policy","uvloop.new_event_loop returns a new unclosed uvloop.Loop instance","uvloop.run executes an async coroutine to completion and returns its result","uvloop.run propagates unhandled exceptions raised inside the coroutine","uvloop.run raises TypeError when passed a non-coroutine object"],"goal":"verify pkg:pypi/uvloop@0.22.1","kind":"HOW","packages":["pkg:pypi/uvloop@0.22.1"],"schemaVersion":1,"symbols":["uvloop.EventLoopPolicy","uvloop.install","uvloop.new_event_loop","uvloop.run"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"pypi","executionContext":"python","language":"python","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"pip","runtime":"python","runtimeVersion":"3.12","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/uvloop@0.22.1"],"schemaVersion":1,"subject":"pkg:pypi/uvloop@0.22.1","symbols":["uvloop.EventLoopPolicy","uvloop.install","uvloop.new_event_loop","uvloop.run"],"verifierAdapter":"python@1"}
requirements.txt
uvloop==0.22.1
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:pypi/uvloop@0.22.1",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/uvloop@0.22.1"
  ],
  "symbols": [
    "uvloop.EventLoopPolicy",
    "uvloop.install",
    "uvloop.new_event_loop",
    "uvloop.run"
  ]
}
test/contract.py
import asyncio
import sys
import uvloop


def test_event_loop_policy() -> None:
    policy = uvloop.EventLoopPolicy()
    assert isinstance(policy, asyncio.AbstractEventLoopPolicy)

    loop = policy.new_event_loop()
    try:
        assert isinstance(loop, uvloop.Loop)
        assert isinstance(loop, asyncio.AbstractEventLoop)
    finally:
        loop.close()


def test_install_policy() -> None:
    uvloop.install()
    current_policy = asyncio.get_event_loop_policy()
    assert isinstance(current_policy, uvloop.EventLoopPolicy)


def test_new_event_loop() -> None:
    loop = uvloop.new_event_loop()
    try:
        assert isinstance(loop, uvloop.Loop)
        assert not loop.is_running()
        assert not loop.is_closed()

        async def compute() -> int:
            return 42

        res = loop.run_until_complete(compute())
        assert res == 42
    finally:
        loop.close()
    assert loop.is_closed()


def test_run_success() -> None:
    async def fetch_payload():
        await asyncio.sleep(0.01)
        return {"status": "ok", "items": [1, 2, 3]}

    result = uvloop.run(fetch_payload())
    assert result == {"status": "ok", "items": [1, 2, 3]}


def test_run_exception() -> None:
    async def faulty_task():
        await asyncio.sleep(0.01)
        raise ValueError("simulated execution error")

    try:
        uvloop.run(faulty_task())
        raise AssertionError("Expected ValueError from uvloop.run")
    except ValueError as exc:
        assert str(exc) == "simulated execution error"


def test_run_type_error() -> None:
    try:
        uvloop.run("not a coroutine")  # type: ignore
        raise AssertionError("Expected TypeError when passing non-coroutine to uvloop.run")
    except TypeError:
        pass


def main() -> None:
    test_event_loop_policy()
    test_install_policy()
    test_new_event_loop()
    test_run_success()
    test_run_exception()
    test_run_type_error()
    print("All uvloop contract assertions passed successfully.")


if __name__ == "__main__":
    main()

オリジンシーダー

匿名