Skip to content

Preserve caller baskets during legacy int-to-float casting - #783

Open
pengpengyi92 wants to merge 2 commits into
Point72:mainfrom
pengpengyi92:codex/preserve-legacy-input-baskets
Open

pengpengyi92 wants to merge 2 commits into
Point72:mainfrom
pengpengyi92:codex/preserve-legacy-input-baskets

Conversation

@pengpengyi92

Copy link
Copy Markdown

Summary

Addresses the remaining legacy-resolver behavior in #181. On current main, with CSP_PYDANTIC set to the empty string before importing CSP, passing an int list/dict basket to a float-basket input still replaces entries in the caller's container with float-cast edges. Reusing that basket as int input can then fail. The Pydantic path already preserves these inputs and is unchanged.

Make a shallow copy on the first required cast, update the resolved basket instead of the original, and reuse that copy for subsequent casts. Baskets that require no cast do not incur a copy in this path. No C++ or public API changes.

Regression tests

  • The graph reproducer from Casting of ts[int] to ts[float] as part of type checking will mutate input baskets in-place, which can lead to downstream errors. #181 asserts the original int edges remain available for downstream casts.
  • A node runtime test covers multiple int entries mixed with existing float entries in both list and dict baskets, original-edge identity, and a real float output of 11.0.
  • Both tests run under both validators; they are not skipped in legacy mode.
  • Against unchanged main c7d0aded32cf9b6c969490a9a7a55376476e7464, the exact two new tests fail under legacy validation due to mutated edge identity. With this patch both pass; under Pydantic they pass before and after.

This branch is based directly on upstream main and does not include #779.

Verification

Windows x64; Python 3.12.14; Pydantic 2.14.1; pytest 9.1.1.

python -m pytest csp/tests/test_type_checking.py csp/tests/test_parsing.py csp/tests/test_typing.py csp/tests/impl/wiring csp/tests/impl/types csp/tests/impl/test_pushadapter.py csp/tests/impl/test_pulladapter.py csp/tests/impl/test_outputadapter.py csp/tests/impl/test_pushpulladapter.py -q -p no:cacheprovider --tb=short

145 passed, 2 skipped, exit 0 (plus 5 passing unittest subtests).

Legacy mode must be selected before importing CSP, for example:

import os
os.environ["CSP_PYDANTIC"] = ""
import pytest
raise SystemExit(pytest.main([
    "csp/tests/test_type_checking.py", "csp/tests/test_parsing.py",
    "csp/tests/test_typing.py", "csp/tests/test_baskets.py",
    "csp/tests/test_basketlib.py", "-k", "not test_literal_typing", "-q",
]))

61 passed, 1 explicitly deselected, exit 0. Without excluding the known Literal case, the three typing/parsing files give 48 passed, 1 failed. Unmodified upstream in the same environment gives 46 passed, 1 failed, with the identical test_literal_typing failure. That pre-existing failure is not fixed or hidden by this PR.

Ruff check/format on the changed files and git diff --check: PASS.

Local runs use checked-out Python source with official CSP 0.19.1 Windows wheel native libraries. No native source rebuild, Linux/macOS matrix or full service-dependent suite was run. Runtime/memory performance has not been benchmarked. Maintainer CI and review remain required; no upstream acceptance is implied.

Signed-off-by: PP1 <74917296+pengpengyi92@users.noreply.github.com>
Signed-off-by: PP1 <74917296+pengpengyi92@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant