CodeSampleX

Exemplo

typing-extensions 4.16.0: typing_extensions.get_type_hints

Amostra verificada para pypi typing-extensions 4.16.0: typing_extensions.get_type_hints. O contrato rodou em python 3.12 · linux debian/x64 · docker e passou.

sha256:25be1b8c402ce3ec5f8dd6c464f47158cf6de4db3dff26eeae0f3305c3660640

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado python linux 24 · ubuntu · glibc 2.39 x64 python python pip

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
python 3.12 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · python@1python:3.12-slim@sha256:09f7da3bc104…
2026-09-05

Caso

HOW
Objetivo
verify typing_extensions.get_type_hints in pkg:pypi/typing-extensions@4.16.0
Pacotes
Símbolos
  • typing_extensions.get_type_hints
Ambiente
python
Criado
2026-09-05T23:35:27Z

Contrato

  1. get_type_hints resolves function parameter and return type annotations into concrete types.
  2. get_type_hints evaluates forward references defined as string literals using globalns and localns.
  3. get_type_hints unwraps Annotated metadata by default, returning the underlying type.
  4. get_type_hints preserves Annotated metadata when include_extras=True.
  5. get_type_hints resolves inherited class attributes across class inheritance hierarchy.
  6. get_type_hints raises TypeError for objects that cannot have type annotations.

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

NOTES.md
# typing_extensions.get_type_hints API contract

This sample pins `typing-extensions` 4.16.0 and verifies `typing_extensions.get_type_hints` for type annotation evaluation and introspection.

The contract verifies:
- `get_type_hints` resolves function parameter and return type annotations into concrete types.
- `get_type_hints` evaluates forward references defined as string literals using globalns and localns.
- `get_type_hints` unwraps Annotated metadata by default (`include_extras=False`), returning the underlying type.
- `get_type_hints` preserves Annotated metadata when `include_extras=True`.
- `get_type_hints` resolves inherited class attributes across class inheritance hierarchy.
- `get_type_hints` raises TypeError for objects that cannot have type annotations and returns empty dict for unannotated objects.
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 typing_extensions.get_type_hints in pkg:pypi/typing-extensions@4.16.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:pypi/typing-extensions@4.16.0
Demonstrate these symbols/APIs:
  - typing_extensions.get_type_hints

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:734381c2a515ff0d1210280bd6ba0cc83ae0f7644a53be893d0607247ea3e42d","contract":["get_type_hints resolves function parameter and return type annotations into concrete types.","get_type_hints evaluates forward references defined as string literals using globalns and localns.","get_type_hints unwraps Annotated metadata by default, returning the underlying type.","get_type_hints preserves Annotated metadata when include_extras=True.","get_type_hints resolves inherited class attributes across class inheritance hierarchy.","get_type_hints raises TypeError for objects that cannot have type annotations."],"goal":"verify typing_extensions.get_type_hints in pkg:pypi/typing-extensions@4.16.0","kind":"HOW","packages":["pkg:pypi/typing-extensions@4.16.0"],"schemaVersion":1,"symbols":["typing_extensions.get_type_hints"]},"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/typing-extensions@4.16.0"],"schemaVersion":1,"subject":"pkg:pypi/typing-extensions@4.16.0","symbols":["typing_extensions.get_type_hints"],"verifierAdapter":"python@1"}
requirements.txt
typing-extensions==4.16.0
spec.json
{
  "schemaVersion": 1,
  "goal": "verify typing_extensions.get_type_hints in pkg:pypi/typing-extensions@4.16.0",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/typing-extensions@4.16.0"
  ],
  "symbols": [
    "typing_extensions.get_type_hints"
  ]
}
test/contract.py
from typing import Annotated, Optional, get_args, get_origin
from typing_extensions import get_type_hints

# 1. Resolves function parameter and return type annotations into concrete types
def calculate_area(length: int, width: float) -> float:
    return float(length * width)

fn_hints = get_type_hints(calculate_area)
assert fn_hints == {"length": int, "width": float, "return": float}, f"Unexpected function hints: {fn_hints}"

# 2. Evaluates forward references defined as string literals using globalns and localns
class Node:
    pass

def traverse(node: "Node", depth: "CustomInt") -> "Optional[Node]":
    return node if depth > 0 else None

local_env = {"CustomInt": int}
fwd_hints = get_type_hints(traverse, localns=local_env)
assert fwd_hints["node"] is Node, f"Expected Node, got {fwd_hints['node']}"
assert fwd_hints["depth"] is int, f"Expected int, got {fwd_hints['depth']}"
assert fwd_hints["return"] == Optional[Node], f"Expected Optional[Node], got {fwd_hints['return']}"

# 3. Unwraps Annotated metadata by default, returning the underlying type
def process_data(value: Annotated[int, "metadata", 42]) -> Annotated[str, "result"]:
    return str(value)

unwrapped_hints = get_type_hints(process_data, include_extras=False)
assert unwrapped_hints["value"] is int, f"Expected unwrapped int, got {unwrapped_hints['value']}"
assert unwrapped_hints["return"] is str, f"Expected unwrapped str, got {unwrapped_hints['return']}"

# 4. Preserves Annotated metadata when include_extras=True
extras_hints = get_type_hints(process_data, include_extras=True)
assert get_origin(extras_hints["value"]) is Annotated
assert get_args(extras_hints["value"]) == (int, "metadata", 42)
assert get_origin(extras_hints["return"]) is Annotated
assert get_args(extras_hints["return"]) == (str, "result")

# 5. Resolves inherited class attributes across class inheritance hierarchy
class BaseEntity:
    id: int
    name: str

class Account(BaseEntity):
    balance: float

class PremiumAccount(Account):
    tier: str

class_hints = get_type_hints(PremiumAccount)
assert class_hints == {
    "id": int,
    "name": str,
    "balance": float,
    "tier": str,
}, f"Unexpected class inheritance hints: {class_hints}"

# 6. Raises TypeError for objects that cannot have type annotations
try:
    get_type_hints(12345)
    raise AssertionError("get_type_hints on integer must raise TypeError")
except TypeError:
    pass

try:
    get_type_hints("invalid_object")
    raise AssertionError("get_type_hints on string must raise TypeError")
except TypeError:
    pass

def no_annotations(x, y):
    return x + y

assert get_type_hints(no_annotations) == {}, "Unannotated function must return empty dictionary"

print("CONTRACT PASS: pkg:pypi/typing-extensions@4.16.0 verified offline")

Seeder de origem

anônimo