샘플
pyyaml 6.0.3: yaml.constructor.ConstructorError
검증된 샘플 — pypi pyyaml 6.0.3: yaml.constructor.ConstructorError. python 3.12 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다.
sha256:2fa3cf88ea97e994d418f6ccc555e56eec94fe7636a22830e6e571c8af968944
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
linux 24 · ubuntu · glibc 2.39 x64 pip
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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 |
케이스
HOW- 목표
- verify yaml.constructor.ConstructorError in pkg:pypi/pyyaml@6.0.3
- 패키지
- 심벌
-
- yaml.constructor.ConstructorError
- 생성일
- 2026-09-05T18:29:48Z
컨트랙트
- assert ConstructorError inherits from MarkedYAMLError and YAMLError and supports custom instantiation
- assert safe loading unhashable mapping keys raises ConstructorError with unhashable key problem message
- assert safe loading unknown tag without registered constructor raises ConstructorError
- assert safe loading malformed base64 binary scalar raises ConstructorError
파일
- PROMPT.md
- csx.json
- pyproject.toml
- requirements.txt
- sample.py
- spec.json
- test/contract.py
소스
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 yaml.constructor.ConstructorError in pkg:pypi/pyyaml@6.0.3
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:pypi/pyyaml@6.0.3
Demonstrate these symbols/APIs:
- yaml.constructor.ConstructorError
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.
{"case":{"caseId":"case:sha256:aef821b22f028152d08f372e2a4ce7efdb166985439c7cae8f4a8b5c28308c0a","contract":["assert ConstructorError inherits from MarkedYAMLError and YAMLError and supports custom instantiation","assert safe loading unhashable mapping keys raises ConstructorError with unhashable key problem message","assert safe loading unknown tag without registered constructor raises ConstructorError","assert safe loading malformed base64 binary scalar raises ConstructorError"],"goal":"verify yaml.constructor.ConstructorError in pkg:pypi/pyyaml@6.0.3","kind":"HOW","packages":["pkg:pypi/pyyaml@6.0.3"],"schemaVersion":1,"symbols":["yaml.constructor.ConstructorError"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"pypi","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"pip","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/pyyaml@6.0.3"],"schemaVersion":1,"subject":"pkg:pypi/pyyaml@6.0.3","symbols":["yaml.constructor.ConstructorError"],"verifierAdapter":"python@1"}
[project]
name = "verify-pyyaml-constructor-error"
version = "0.1.0"
dependencies = [
"pyyaml==6.0.3",
]
pyyaml==6.0.3
"""Sample demonstrating yaml.constructor.ConstructorError handling and usage in PyYAML."""
from typing import Any, Optional, Tuple
import yaml
from yaml.constructor import ConstructorError
from yaml.error import MarkedYAMLError, YAMLError
def parse_yaml_safely(yaml_str: str) -> Tuple[bool, Any, Optional[ConstructorError]]:
"""Attempt to safely load a YAML string, catching ConstructorError if present."""
try:
data = yaml.safe_load(yaml_str)
return True, data, None
except ConstructorError as exc:
return False, None, exc
def expect_unhashable_key_error(yaml_str: str) -> ConstructorError:
"""Load YAML that has an unhashable mapping key, asserting ConstructorError is raised."""
try:
yaml.safe_load(yaml_str)
except ConstructorError as exc:
return exc
raise AssertionError("Expected ConstructorError was not raised")
def expect_unknown_tag_error(yaml_str: str) -> ConstructorError:
"""Load YAML with an undefined tag, asserting ConstructorError is raised."""
try:
yaml.safe_load(yaml_str)
except ConstructorError as exc:
return exc
raise AssertionError("Expected ConstructorError was not raised")
def expect_invalid_binary_error(yaml_str: str) -> ConstructorError:
"""Load YAML with malformed base64 binary scalar, asserting ConstructorError is raised."""
try:
yaml.safe_load(yaml_str)
except ConstructorError as exc:
return exc
raise AssertionError("Expected ConstructorError was not raised")
def build_constructor_error(
context: Optional[str] = None,
problem: Optional[str] = None,
note: Optional[str] = None,
) -> ConstructorError:
"""Construct an explicit ConstructorError instance with contextual information."""
return ConstructorError(
context=context,
context_mark=None,
problem=problem,
problem_mark=None,
note=note,
)
{
"schemaVersion": 1,
"goal": "verify yaml.constructor.ConstructorError in pkg:pypi/pyyaml@6.0.3",
"kind": "HOW",
"packages": [
"pkg:pypi/pyyaml@6.0.3"
],
"symbols": [
"yaml.constructor.ConstructorError"
]
}
"""Contract verification test for yaml.constructor.ConstructorError in pkg:pypi/pyyaml@6.0.3."""
import os
import sys
# Ensure project root is on sys.path for local module imports
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import yaml
from yaml.constructor import ConstructorError
from yaml.error import MarkedYAMLError, YAMLError
from sample import (
parse_yaml_safely,
expect_unhashable_key_error,
expect_unknown_tag_error,
expect_invalid_binary_error,
build_constructor_error,
)
def test_constructor_error_hierarchy_and_instantiation() -> None:
"""assert ConstructorError inherits from MarkedYAMLError and YAMLError and supports custom instantiation"""
assert issubclass(ConstructorError, MarkedYAMLError)
assert issubclass(ConstructorError, YAMLError)
err = build_constructor_error(
context="while constructing custom mapping",
problem="duplicate key encountered",
note="keys must be unique in this schema",
)
assert isinstance(err, ConstructorError)
assert isinstance(err, MarkedYAMLError)
assert isinstance(err, YAMLError)
assert err.context == "while constructing custom mapping"
assert err.problem == "duplicate key encountered"
assert err.note == "keys must be unique in this schema"
err_str = str(err)
assert "while constructing custom mapping" in err_str
assert "duplicate key encountered" in err_str
assert "keys must be unique in this schema" in err_str
def test_unhashable_key_raises_constructor_error() -> None:
"""assert safe loading unhashable mapping keys raises ConstructorError with unhashable key problem message"""
unhashable_yaml = "{ [1, 2]: sample_value }"
success, data, err = parse_yaml_safely(unhashable_yaml)
assert success is False
assert data is None
assert isinstance(err, ConstructorError)
raised = expect_unhashable_key_error(unhashable_yaml)
assert raised.problem == "found unhashable key"
assert raised.context == "while constructing a mapping"
assert "found unhashable key" in str(raised)
def test_unknown_tag_raises_constructor_error() -> None:
"""assert safe loading unknown tag without registered constructor raises ConstructorError"""
unknown_tag_yaml = "!customUndefinedTag test_value"
success, data, err = parse_yaml_safely(unknown_tag_yaml)
assert success is False
assert data is None
assert isinstance(err, ConstructorError)
raised = expect_unknown_tag_error(unknown_tag_yaml)
assert "could not determine a constructor for the tag" in str(raised)
assert "!customUndefinedTag" in str(raised)
def test_invalid_binary_scalar_raises_constructor_error() -> None:
"""assert safe loading malformed base64 binary scalar raises ConstructorError"""
invalid_binary_yaml = "!!binary 'not_valid_base64!?*#'"
success, data, err = parse_yaml_safely(invalid_binary_yaml)
assert success is False
assert data is None
assert isinstance(err, ConstructorError)
raised = expect_invalid_binary_error(invalid_binary_yaml)
assert "failed to decode base64 data" in str(raised)
def main() -> None:
test_constructor_error_hierarchy_and_instantiation()
test_unhashable_key_raises_constructor_error()
test_unknown_tag_raises_constructor_error()
test_invalid_binary_scalar_raises_constructor_error()
print("All contract assertions passed.")
if __name__ == "__main__":
main()
오리진 시더
익명