fix: treat i2's NotSet signature default as required / no default - #19
Merged
Merged
Conversation
`mk_input_schema_from_func` and `ParamsSpecifier.from_func` read defaults through the new `schema_tools.param_default`, which maps i2's `NotSet` sentinel to `Parameter.empty`. So a signature with NotSet defaults (as a re-landed i2mint/i2#88 FuncFactory would show) keeps its params required and yields a JSON-serializable OpenAPI spec, identical to the plain one. No-op for current signatures. Uses `i2.is_not_set` when available, else falls back on `i2.deco.NotSet`, so the i2 requirement is unchanged. Refs i2mint/i2#48 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…(review follow-up) Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Member
Author
|
Independent refute-review (sub-agent): no blocking defects. It exercised a real Follow-ups applied:
Noted, not changed:
|
- tests: http2py's mk_request_func_from_openapi_spec takes method as keyword-only since 2025-08; the positional call broke collection of simple_run_process_test.py (master CI red since then). - mk_app: multi-API routes like 'foo_api' (as in its own doctest) are now mounted at '/foo_api'; bottle >= 0.13 and aiohttp reject prefixes without a leading slash, so the documented usage raised ValueError. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
What
Step 2 of the re-land plan in i2mint/i2#48, for
py2http: treat i2'sNotSetsentinel as a signature default the same way asinspect.Parameter.empty("required, no default").py2http.schema_tools.param_default(param): returnsparam.default, orParameter.emptywhen it isNotSet.mk_input_schema_from_func(OpenAPI request schema:default,required, type inference) andParamsSpecifier.from_func. The latter also loses a dead loop whose result was immediately overwritten.Why
i2mint/i2#88 gave
FuncFactorysignaturesNotSetdefaults and was reverted in i2mint/i2#89. One reason was thatmk_routes_and_openapi_specs([factory])then produced a spec thatjson.dumpsrefused ("Sentinel is not JSON serializable"), with the params no longer required. With this PR, the spec for aNotSet-defaulted signature is identical to the plain one.Decision:
NotSetmeans required. The plan left open whether such params should be required or optional in the schema. I chose required: it keeps py2http's output for aFuncFactoryexactly as it is today, before and after #88. It also matches whatNotSetstands for: the wrapped function will need the value by the time it is called. Making them optional would be a separate, deliberate API change.No-op against the current i2: no current signature carries
NotSet.i2 compatibility (decision)
Uses
i2.is_not_set(added in i2mint/i2#91, i2 0.1.74) when available, otherwise falls back oni2.deco.NotSet(present since 2023). The i2 requirement is not changed.Tests
py2http/tests/test_not_set_defaults.py: the input schema and the whole OpenAPI spec for aNotSet-defaultedfooequal those of the plainfoo, the spec JSON-serializes, andParamsSpecifieruses its_dflt_default. There is also a doctest inmk_input_schema_from_func. 3 of the 4 tests fail without the fix (the 4th checks the fixture).Gate
schema_tools/decoratorsdoctests: 15 passed with i2 master (nativeis_not_set) and with i2 0.1.73 from PyPI (fallback path).pytest --doctest-modules py2http(py3.12, scrap/examples ignored): 26 passed, 1 failed, 2 errors. Master gives 21 passed with the same 1 failure and 2 errors, all pre-existing: theservice.mk_appdoctest, andtests/simple_run_process_test.pycallinghttp2py.mk_request_func_from_openapi_specwith a stale signature. Hosted CI on master has been red since 2025-08 for pre-existing reasons.extrude(tested below);peruseis not on this box.🤖 Generated with Claude Code