fix: avoid non-string key in Outputs class namespace - #763
Closed
thea-ishida wants to merge 1 commit into
Closed
thea-ishida wants to merge 1 commit into
thea-ishida wants to merge 1 commit into
Conversation
csp.Outputs(...) builds a class via type(name, bases, namespace). For a single unnamed output, that namespace carried a literal None key (used internally to mark 'no name'), which becomes a non-string entry in the resulting class's __dict__. CPython 3.13 warns on this: RuntimeWarning: non-string key in the __dict__ of class Outputs The None entry is only ever read back via __annotations__[None], so it's safe to drop the top-level entry right before constructing the class. Added a regression test that fails (via warnings-as-errors) without the fix, covering both named and unnamed outputs, and a full node/graph run. Reproduced the warning under Python 3.13.15 and verified the fix resolves it while preserving existing named/unnamed/pydantic-model output behavior. Fixes Point72#665 Signed-off-by: Thea <thea.ishida@gmail.com>
thea-ishida
requested review from
AdamGlustein,
alexddobkin,
robambalu and
svatasoiu
as code owners
September 16, 2026 19:02
Collaborator
|
On deeper review of this this PR does look correct, popping None should suffice |
Collaborator
|
was hoping to get this in soon but dont want to wait on a response so will close and open a new one |
Collaborator
Contributor
Author
|
@robambalu Thanks for merging this, and sorry I missed the test-removal request. Happy to keep contributing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #665.
Outputs.__new__keys a single unnamed output askwargs[None]and then passeskwargsstraight totype("Outputs", (Outputs,), kwargs). Since a non-string key in a class namespace triggers a warning on Python 3.13+:which fires on plain
import csp. TheNonekey is only needed in__annotations__(that copy is taken earlier, and_extract_outputs_from_return_annotationreads the unnamed output back from there) and by_make_pydantic_outputs, which runs before this point. So it's safe to pop it offkwargsright before thetype()call — the annotations dict keeps it, the class namespace doesn't.Added a regression test (
test_outputs_no_non_string_key_warningincsp/tests/test_parsing.py) covering unnamed outputs, named outputs, and a full node/graph run, withRuntimeWarningpromoted to an error.Context on prior attempts
This same root cause and fix were independently found three times (#741, #752, and my own earlier #762 — all now closed). #741 was closed with the request to "try running all tests before posting," and neither of the follow-up attempts, including mine, provided that. #762 could not be reopened via the API/CLI (
Could not open the pull request), so I'm opening this fresh PR from the same branch with the verification actually done.Verification
Built csp from source on macOS (vcpkg + the compiled C++ engine) rather than testing against a pip-installed wheel, then ran the full suite against that build:
Zero failures, zero errors. This exercises
Outputsend-to-end: named/unnamed/basket outputs, dynamic outputs, structs, memoization, and the pydantic-model path.I also checked whether the C++ engine reads the
Outputsclass's raw namespace/__dict__anywhere (which would make popping theNonekey insufficient) — it doesn't; the C++ side only ever receives already-resolved output definitions built from__annotations__.Also ran, on the changed files:
ruff checkruff format --checkHappy to make any changes needed.