CodeSampleX

サンプル

sqlalchemy 2.0.51: sql.elements.BinaryExpression

検証済みサンプル — pypi sqlalchemy 2.0.51: sql.elements.BinaryExpression. python 3.12 · linux debian/x64 · docker で contract を実行し、成功しました.

sha256:8fe1f5e5eea816685d88874fea42a289ec038e01bd2bcf9cba005b7a5a7f580a

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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-06

ケース

HOW
ゴール
verify sqlalchemy.sql.elements.BinaryExpression in pkg:pypi/sqlalchemy@2.0.51
パッケージ
シンボル
  • sqlalchemy.sql.elements.BinaryExpression
作成日
2026-09-06T23:57:29Z

コントラクト

  1. sqlalchemy.sql.elements.BinaryExpression represents binary operations between SQL column expressions with left operand, right operand, and operator
  2. sqlalchemy.sql.elements.BinaryExpression can be instantiated directly with left element, right element, and an operator callable
  3. sqlalchemy.sql.elements.BinaryExpression supports bitwise inversion to produce a negated binary expression with corresponding inverted operator
  4. sqlalchemy.sql.elements.BinaryExpression compiles to SQL expression strings with parameter bindings and integrates into SELECT query WHERE clauses

ファイル

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

ソースアーティファクトをダウンロード (tar.gz)

ソース

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 sqlalchemy.sql.elements.BinaryExpression in pkg:pypi/sqlalchemy@2.0.51
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:pypi/sqlalchemy@2.0.51
Demonstrate these symbols/APIs:
  - sqlalchemy.sql.elements.BinaryExpression

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:2afd88ba43fdd366eba59ff07fa4060bb91e03388f8dd2f0c114bdace09959f0","contract":["sqlalchemy.sql.elements.BinaryExpression represents binary operations between SQL column expressions with left operand, right operand, and operator","sqlalchemy.sql.elements.BinaryExpression can be instantiated directly with left element, right element, and an operator callable","sqlalchemy.sql.elements.BinaryExpression supports bitwise inversion to produce a negated binary expression with corresponding inverted operator","sqlalchemy.sql.elements.BinaryExpression compiles to SQL expression strings with parameter bindings and integrates into SELECT query WHERE clauses"],"goal":"verify sqlalchemy.sql.elements.BinaryExpression in pkg:pypi/sqlalchemy@2.0.51","kind":"HOW","packages":["pkg:pypi/sqlalchemy@2.0.51"],"schemaVersion":1,"symbols":["sqlalchemy.sql.elements.BinaryExpression"]},"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/sqlalchemy@2.0.51"],"schemaVersion":1,"subject":"pkg:pypi/sqlalchemy@2.0.51","symbols":["sqlalchemy.sql.elements.BinaryExpression"],"verifierAdapter":"python@1"}
requirements.txt
sqlalchemy==2.0.51
sample.py
"""Demonstration of SQL binary expressions using sqlalchemy.sql.elements.BinaryExpression."""

from typing import Any, Callable, Tuple
import operator
import sqlalchemy as sa
from sqlalchemy.sql.elements import BinaryExpression
from sqlalchemy.dialects import sqlite


def create_binary_comparison(
    column_name: str,
    value: Any,
) -> BinaryExpression:
    """Create a BinaryExpression using a column comparison operator."""
    col = sa.column(column_name)
    expr = col == value
    if not isinstance(expr, BinaryExpression):
        raise TypeError(f"Expected BinaryExpression, got {type(expr)}")
    return expr


def instantiate_binary_expression(
    column_name: str,
    value: Any,
    op: Callable[..., Any] = operator.gt,
) -> BinaryExpression:
    """Explicitly instantiate a BinaryExpression with left, right, and operator."""
    col = sa.column(column_name)
    val = sa.literal(value)
    return BinaryExpression(col, val, op)


def negate_binary_expression(expr: BinaryExpression) -> BinaryExpression:
    """Invert a BinaryExpression using the bitwise NOT operator."""
    negated = ~expr
    if not isinstance(negated, BinaryExpression):
        raise TypeError(f"Expected BinaryExpression after negation, got {type(negated)}")
    return negated


def inspect_binary_expression(expr: BinaryExpression) -> Tuple[Any, Any, Callable[..., Any]]:
    """Inspect the operands and operator of a BinaryExpression."""
    return expr.left, expr.right, expr.operator


def compile_binary_expression(expr: BinaryExpression, literal_binds: bool = True) -> str:
    """Compile a BinaryExpression to SQL string representation."""
    return str(expr.compile(dialect=sqlite.dialect(), compile_kwargs={"literal_binds": literal_binds}))


def build_filtered_query(table_name: str, expr: BinaryExpression) -> str:
    """Build and compile a SELECT statement filtered by the BinaryExpression."""
    table = sa.table(table_name, expr.left)
    stmt = sa.select(table).where(expr)
    return str(stmt.compile(dialect=sqlite.dialect(), compile_kwargs={"literal_binds": True}))
spec.json
{
  "schemaVersion": 1,
  "goal": "verify sqlalchemy.sql.elements.BinaryExpression in pkg:pypi/sqlalchemy@2.0.51",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/sqlalchemy@2.0.51"
  ],
  "symbols": [
    "sqlalchemy.sql.elements.BinaryExpression"
  ]
}
test/contract.py
"""Contract verification tests for sqlalchemy.sql.elements.BinaryExpression."""

import os
import sys
import operator

# Ensure sample root directory is in sys.path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from sqlalchemy.sql.elements import BinaryExpression, BindParameter, ColumnClause
from sqlalchemy.dialects import sqlite
import sample


def test_binary_expression_representation() -> None:
    """Assertion 1: sqlalchemy.sql.elements.BinaryExpression represents binary operations between SQL column expressions with left operand, right operand, and operator."""
    expr = sample.create_binary_comparison("status", "active")

    assert isinstance(expr, BinaryExpression)
    left, right, op = sample.inspect_binary_expression(expr)

    assert isinstance(left, ColumnClause)
    assert left.name == "status"
    assert isinstance(right, BindParameter)
    assert right.value == "active"
    assert op is operator.eq


def test_direct_instantiation() -> None:
    """Assertion 2: sqlalchemy.sql.elements.BinaryExpression can be instantiated directly with left element, right element, and an operator callable."""
    gt_expr = sample.instantiate_binary_expression("score", 90, operator.gt)

    assert isinstance(gt_expr, BinaryExpression)
    assert gt_expr.left.name == "score"
    assert gt_expr.right.value == 90
    assert gt_expr.operator is operator.gt

    add_expr = sample.instantiate_binary_expression("score", 10, operator.add)
    assert isinstance(add_expr, BinaryExpression)
    assert add_expr.operator is operator.add


def test_negation_inversion() -> None:
    """Assertion 3: sqlalchemy.sql.elements.BinaryExpression supports bitwise inversion to produce a negated binary expression with corresponding inverted operator."""
    expr = sample.create_binary_comparison("status", "active")
    negated = sample.negate_binary_expression(expr)

    assert isinstance(negated, BinaryExpression)
    assert negated.operator is operator.ne
    assert negated.left.name == "status"
    assert negated.right.value == "active"

    # Double negation restores equality semantics
    double_negated = sample.negate_binary_expression(negated)
    assert isinstance(double_negated, BinaryExpression)
    assert double_negated.operator is operator.eq


def test_compilation_and_select_integration() -> None:
    """Assertion 4: sqlalchemy.sql.elements.BinaryExpression compiles to SQL expression strings with parameter bindings and integrates into SELECT query WHERE clauses."""
    expr = sample.create_binary_comparison("status", "active")

    # Compile with literal binds
    compiled_literal = sample.compile_binary_expression(expr, literal_binds=True)
    assert compiled_literal == "status = 'active'"

    # Compile with parameter placeholder
    compiled_param = str(expr.compile(dialect=sqlite.dialect()))
    assert compiled_param == "status = ?"

    # Query integration in SELECT statement
    query_str = sample.build_filtered_query("users", expr)
    assert "WHERE users.status = 'active'" in query_str


def main() -> None:
    test_binary_expression_representation()
    test_direct_instantiation()
    test_negation_inversion()
    test_compilation_and_select_integration()
    print("All sqlalchemy.sql.elements.BinaryExpression contract assertions passed successfully.")


if __name__ == "__main__":
    main()

オリジンシーダー

匿名