Repository navigation
Conversation
A dataclass or pydantic field with a default reached the caller as a required socket, so a graph that left it alone failed with a missing required input naming that field. - Mark a field optional when it declares a default or a default factory, in the pydantic, dataclass, and dynamic branches of `from_model`. - Read the factory's presence only, never calling it, so a field's default value is still copied only from a plain default. - Apply requiredness to namespace fields too, which carry no default value but may be omitted just the same. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Three of the new tests asserted the same thing twice in one function, once for a dataclass and once for a pydantic model, so a failure did not say which kind broke. - Parametrize them over the two model kinds, with `dataclass` and `pydantic` ids. - Build the default-factory models from a per-case factory, so each case asserts its own factory went uncalled. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Three ways of giving a socket a default left it reported as required, so a caller who relied on the default was told the input was missing. - `namespace(b=(int, 5))`, and the same tuple form among a dynamic namespace's fixed fields, now yield an optional socket. - `set_default` marks the leaf optional; `unset_default` makes it required again, unless it had no default to lose. - A leaf named by the mapping default of a namespace parameter comes out optional; the namespaces the mapping descends into keep their requiredness, since the mapping need not name every field below them. - One test per path, each failing without the change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #174 +/- ##
==========================================
+ Coverage 89.68% 89.82% +0.14%
==========================================
Files 81 81
Lines 8984 9109 +125
==========================================
+ Hits 8057 8182 +125
Misses 927 927 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
elinscott
added a commit
to elinscott/node-graph
that referenced
this pull request
Aug 14, 2026
# Conflicts: # src/node_graph/socket_spec.py
elinscott
added a commit
to elinscott/node-graph
that referenced
this pull request
Aug 17, 2026
Resolution notes, all of it integration between two open pull requests: - socket_spec.py: scinode#159 reads a Pydantic field's annotation through `_pydantic_field_annotation` and scinode#174 derives requiredness from the field's default at the same two sites; both are kept.
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.
Giving a socket a default still left it reported as required, so a caller who relied on the default was told the input was missing. Given
bcarries the default it was given and is still required, so nothing downstream can tell it apart from an input the caller simply never supplied.This stacks on #173, which fixed the same defect for a dataclass or pydantic field. That PR listed three paths it did not cover; these are those three:
namespace(b=(int, 5)), which is also how a dynamic namespace's fixed fields are declaredset_default(spec, "b", 5)def f(cfg: ns(x=int, y=int) = {"y": 3}), which sets defaults on the leaves the mapping namesChanges
Mark a leaf optional when any of those three gives it a default. That leaves
SocketSpec(identifier, default=...), built by hand, as the only remaining way to end up with a default andrequired=True— see below.set_defaultis a mutation rather than a construction, so it needs an inverse:unset_defaultmakes the leaf required again. It restores requiredness by the same rule that removed it, so it only reverses optionality this mechanism introduced; a leaf whose optionality was declared some other way — aNotRequiredTypedDict key, or an explicitrequired=False— is currently made required too, which is wrong and worth fixing separately.Inner namespaces are left alone here, departing from #173, which marked a defaulted namespace field optional. The two construction paths refuse a namespace default outright, so no namespace case arises; and a mapping default names only some of the leaves below a namespace, so descending into one says nothing about whether the caller may skip it. #173's namespaces were different: a field annotated
Optional[Sub] = Noneis a statement about the whole namespace.Following #173, requiredness is set to
Falserather than left asNone, sinceSocketMeta.to_dictdropsNoneandfrom_dictthen restores theTruedefault.What is left
A
SocketSpecconstructed by hand with a default — asWhile.max_iterationsandIf.invert_conditionare intasks/builtins.py— still comes out required. Deriving requiredness inSocketSpec.__post_init__would catch that case and every other one, but it would also rewrite specs restored byfrom_dict, changing how an already-serialized graph deserializes. Decided to separate that decision from this PR.