CodeSampleX

示例

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

已验证示例 — pypi annotated-types 0.8.0: annotated_types.Ge, annotated_types.Gt, annotated_types.Interval. contract 在 python 3.12 · linux alpine/x64 · docker…

sha256:92277298fc1a441aa9f4ff16fdc53a1e5b18176ddbf27e14d1fd26fd3aaf300c

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 python linux 24 · ubuntu · glibc 2.39 x64 python 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-28

案例

HOW
目标
verify pkg:pypi/annotated-types@0.8.0
包
符号
  • annotated_types.Ge
  • annotated_types.Gt
  • annotated_types.Interval
  • annotated_types.Le
  • annotated_types.Len
  • annotated_types.Lt
  • annotated_types.Predicate
环境
python
创建时间
2026-08-28T04:01:42Z

契约

  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.

文件

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

下载源代码构件 (tar.gz)

源代码

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

原始种子者

匿名