CodeSampleX

Ejemplo

annotated-types 0.8.0: annotated_types.Ge, annotated_types.Gt, annotated_types.Interval

Muestra verificada para pypi annotated-types 0.8.0: annotated_types.Ge, annotated_types.Gt, annotated_types.Interval. El contrato se ejecutó en python 3.12 …

sha256:92277298fc1a441aa9f4ff16fdc53a1e5b18176ddbf27e14d1fd26fd3aaf300c

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado python linux 24 · ubuntu · glibc 2.39 x64 python python pip

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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-28

Caso

HOW
Objetivo
verify pkg:pypi/annotated-types@0.8.0
Paquetes
Símbolos
  • annotated_types.Ge
  • annotated_types.Gt
  • annotated_types.Interval
  • annotated_types.Le
  • annotated_types.Len
  • annotated_types.Lt
  • annotated_types.Predicate
Entorno
python
Creado
2026-08-28T04:01:42Z

Contrato

  1. Gt, Ge, Lt, and Le instantiate single-bound inequality constraints inheriting from BaseMetadata and storing their respective bound attributes.
  2. Interval groups upper and lower bounds into an iterable GroupedMetadata object that yields individual Gt, Ge, Lt, and Le constraint instances.
  3. Len expresses minimum and maximum collection length constraints and unpacks into MinLen and MaxLen instances when iterated.
  4. Predicate encapsulates callable validation predicates with customizable string representation and equality semantics.
  5. annotated-types constraint objects integrate with typing.Annotated for function signatures and class attributes, retrievable via typing.get_type_hints.

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

NOTES.md
# annotated-types constraint metadata and typing.Annotated integration

This sample pins `annotated-types` 0.8.0 and verifies core constraint metadata types: `Gt`, `Ge`, `Lt`, `Le`, `Interval`, `Len`, and `Predicate`.

The contract verifies:
- Single-bound inequality constraints (`Gt`, `Ge`, `Lt`, `Le`) inheriting from `BaseMetadata` with frozen immutability and attribute storage (`gt`, `ge`, `lt`, `le`).
- Multi-bound `Interval` implementing `GroupedMetadata` to unpack into single-bound constraints (`Gt`, `Ge`, `Lt`, `Le`) upon iteration.
- Collection sizing metadata `Len(min_length, max_length)` implementing `GroupedMetadata` to unpack into `MinLen` and `MaxLen`.
- Callable predicate metadata `Predicate(func)` holding validation functions with readable string representation (`repr`) and equality semantics.
- Integration with standard `typing.Annotated` for function parameter, return type, and class attribute annotations retrievable via `typing.get_type_hints(..., include_extras=True)` and `typing.get_args(...)`.
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/annotated-types@0.8.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:pypi/annotated-types@0.8.0
Demonstrate these symbols/APIs:
  - annotated_types.Ge
  - annotated_types.Gt
  - annotated_types.Interval
  - annotated_types.Le
  - annotated_types.Len
  - annotated_types.Lt
  - annotated_types.Predicate

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:dea4b69a255757ed79c331c52b4219b2242999d64d30280cf45d820c2a71fb6c","contract":["Gt, Ge, Lt, and Le instantiate single-bound inequality constraints inheriting from BaseMetadata and storing their respective bound attributes.","Interval groups upper and lower bounds into an iterable GroupedMetadata object that yields individual Gt, Ge, Lt, and Le constraint instances.","Len expresses minimum and maximum collection length constraints and unpacks into MinLen and MaxLen instances when iterated.","Predicate encapsulates callable validation predicates with customizable string representation and equality semantics.","annotated-types constraint objects integrate with typing.Annotated for function signatures and class attributes, retrievable via typing.get_type_hints."],"goal":"verify pkg:pypi/annotated-types@0.8.0","kind":"HOW","packages":["pkg:pypi/annotated-types@0.8.0"],"schemaVersion":1,"symbols":["annotated_types.Ge","annotated_types.Gt","annotated_types.Interval","annotated_types.Le","annotated_types.Len","annotated_types.Lt","annotated_types.Predicate"]},"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","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/annotated-types@0.8.0"],"schemaVersion":1,"subject":"pkg:pypi/annotated-types@0.8.0","symbols":["annotated_types.Ge","annotated_types.Gt","annotated_types.Interval","annotated_types.Le","annotated_types.Len","annotated_types.Lt","annotated_types.Predicate"],"verifierAdapter":"python@1"}
requirements.txt
annotated-types==0.8.0
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:pypi/annotated-types@0.8.0",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/annotated-types@0.8.0"
  ],
  "symbols": [
    "annotated_types.Ge",
    "annotated_types.Gt",
    "annotated_types.Interval",
    "annotated_types.Le",
    "annotated_types.Len",
    "annotated_types.Lt",
    "annotated_types.Predicate"
  ]
}
test/contract.py
from typing import Annotated, get_args, get_type_hints
import annotated_types
from annotated_types import (
    BaseMetadata,
    Ge,
    GroupedMetadata,
    Gt,
    Interval,
    Le,
    Len,
    Lt,
    MaxLen,
    MinLen,
    Predicate,
)

# 1. Verify package version
assert hasattr(annotated_types, "__version__"), "annotated_types must define __version__"
assert annotated_types.__version__ == "0.8.0", f"Expected version 0.8.0, got {annotated_types.__version__}"

# 2. Verify single-bound inequality constraints (Gt, Ge, Lt, Le)
assert issubclass(Gt, BaseMetadata)
assert issubclass(Ge, BaseMetadata)
assert issubclass(Lt, BaseMetadata)
assert issubclass(Le, BaseMetadata)

gt10 = Gt(10)
ge0 = Ge(0)
lt100 = Lt(100)
le50 = Le(50)

assert gt10.gt == 10
assert ge0.ge == 0
assert lt100.lt == 100
assert le50.le == 50

assert gt10 == Gt(10)
assert gt10 != Gt(20)
assert hash(gt10) == hash(Gt(10))

assert ge0 == Ge(0)
assert ge0 != Ge(1)

assert lt100 == Lt(100)
assert lt100 != Lt(50)

assert le50 == Le(50)
assert le50 != Le(60)

# 3. Verify Interval and GroupedMetadata unpacking
iv_range = Interval(ge=1, lt=100)
assert isinstance(iv_range, GroupedMetadata)
assert iv_range.ge == 1
assert iv_range.lt == 100
assert iv_range.gt is None
assert iv_range.le is None

unpacked_iv = list(iv_range)
assert unpacked_iv == [Ge(1), Lt(100)]

iv_all = Interval(gt=0, ge=1, lt=10, le=9)
assert list(iv_all) == [Gt(0), Ge(1), Lt(10), Le(9)]

iv_empty = Interval()
assert list(iv_empty) == []

# 4. Verify Len constraint and MinLen/MaxLen unpacking
len_bounded = Len(min_length=2, max_length=20)
assert isinstance(len_bounded, GroupedMetadata)
assert len_bounded.min_length == 2
assert len_bounded.max_length == 20
assert list(len_bounded) == [MinLen(2), MaxLen(20)]

len_min_only = Len(min_length=5)
assert list(len_min_only) == [MinLen(5)]

len_default = Len()
assert len_default.min_length == 0
assert len_default.max_length is None
assert list(len_default) == []

# 5. Verify Predicate metadata and representation
pred_lower = Predicate(str.islower)
assert issubclass(Predicate, BaseMetadata)
assert pred_lower.func is str.islower
assert repr(pred_lower) == "Predicate(str.islower)"
assert pred_lower == Predicate(str.islower)
assert pred_lower != Predicate(str.isupper)

pred_custom = Predicate(lambda x: x % 2 == 0)
assert repr(pred_custom).startswith("Predicate(")

# 6. Verify integration with typing.Annotated and reflection
def process_data(
    score: Annotated[int, Gt(0), Le(100)],
    username: Annotated[str, Len(3, 30), Predicate(str.isalnum)],
    ratio: Annotated[float, Interval(ge=0.0, le=1.0)],
) -> Annotated[bool, Predicate(bool)]:
    return True

hints = get_type_hints(process_data, include_extras=True)
assert "score" in hints and "username" in hints and "ratio" in hints and "return" in hints

score_args = get_args(hints["score"])
assert score_args[0] is int
assert score_args[1] == Gt(0)
assert score_args[2] == Le(100)

user_args = get_args(hints["username"])
assert user_args[0] is str
assert user_args[1] == Len(3, 30)
assert user_args[2] == Predicate(str.isalnum)

ratio_args = get_args(hints["ratio"])
assert ratio_args[0] is float
assert ratio_args[1] == Interval(ge=0.0, le=1.0)

return_args = get_args(hints["return"])
assert return_args[0] is bool
assert return_args[1] == Predicate(bool)

class Record:
    item_count: Annotated[int, Ge(1), Lt(1000)]

record_hints = get_type_hints(Record, include_extras=True)
count_args = get_args(record_hints["item_count"])
assert count_args[0] is int
assert count_args[1] == Ge(1)
assert count_args[2] == Lt(1000)

print("CONTRACT PASS: pkg:pypi/annotated-types@0.8.0 verified offline")

Seeder de origen

anónimo