CodeSampleX

Exemple

uvloop 0.22.1: EventLoopPolicy, install, new_event_loop

Échantillon vérifié pour pypi uvloop 0.22.1: EventLoopPolicy, install, new_event_loop. Le contrat s'est exécuté sur python 3.12 · linux alpine/x64 · docker…

sha256:2ce47866a5864ba793f7f51ce3a1dc73d5d710e5d46be32bc3511c1870f071bf

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré python 3.12 linux 24 · ubuntu · glibc 2.39 x64 python 3.12 python pip

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify pkg:pypi/uvloop@0.22.1
Paquets
Symboles
  • uvloop.EventLoopPolicy
  • uvloop.install
  • uvloop.new_event_loop
  • uvloop.run
Environnement
python 3.12
Créé
2026-08-27T18:07:40Z

Contrat

  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

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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()

Seeder d'origine

anonyme