Repository navigation
Description
(GPT Astra)
Goal
Restore passing Const proxies directly into component methods, including custom template_data(), once proxies can behave transparently enough for ordinary Python code.
The desired behavior is that component authors can use values normally without knowing they are proxies, optionally inspect their constant status, and forward them through template_data() so Citry retains the constant marker and can precompute the corresponding template expressions.
Context
The remaining input-wrapper bugs and the immediate fix belong in #107. The implemented fix consumes an outer Const marker for each field before component code runs and preserves constant information separately. Ordinary containers with manually nested markers remain unchanged. The default kwargs-to-template mapping retains that information, and custom template_data() outputs recover it when the final key and object identity match the normalized marked input. Renamed or replaced stable outputs need an explicit Const(...) declaration. This issue tracks the future return to proxy forwarding through custom callbacks, not that immediate fix.
A separate proxy currently fails identity checks such as value is True, value is None, and comparisons with caller-owned sentinels. Other Python APIs and proxy protocols also expose differences. Restoring forwarding must preserve ordinary user-code behavior, rather than require component authors to unwrap values themselves.
Performance outcome after the workaround
After implementing ordinary callback values, same-key/object-identity recovery, root-only deep unwrapping, and the subsequent dictionary-bookkeeping optimizations, the large Citry benchmark ended with 10.7% longer warm render times for the ordinary variant and 14.4% longer for the simple variant, compared with the historical recorded release from before these unwrapping changes.
| Large benchmark variant | Historical recorded release | Final implementation | Longer render time |
|---|---|---|---|
| Ordinary | 33.77 ms | 37.40 ms | 10.7% |
| Simple | 24.62 ms | 28.18 ms | 14.4% |
The historical reference is benchmarks/results/publication-20260910-release-0.5.0.json. The final measurement used ten interleaved fresh-process blocks per source/variant, six initial renders and 80 warm renders per worker, retaining outputs with normal garbage collection. The simple variant enables the simple-component path for three selected component classes in the same large scenario.
These percentages describe the outcome against an earlier recorded release, not a matched estimate of the cost caused solely by unwrapping or by identity checks. The final matched comparison against the implementation immediately before the bookkeeping optimization reduced warm render time by 6.2% (ordinary) and 4.8% (simple). The application-output and browser-manifest checks passed.
This remaining performance difference is another reason to revisit transparent proxy forwarding when upstream capabilities permit it. The present correctness fix is accepted; this issue continues to track future proxy restoration, while the reported bugs belong in #107.
Compatibility gaps beyond is
These cases were reproduced with Citry's current Const proxy and wrapt 2.2.2. Some reflect Python runtime constraints; others depend on the proxy class and the methods it implements.
| Case | What breaks |
|---|---|
type() / id() |
Expose the wrapper's type and identity rather than the wrapped object's. |
Regex, str.join, os.fspath, getattr attribute names |
Reject wrapped strings even when isinstance(value, str) succeeds. |
JSON serialization / memoryview |
Reject wrapped values that work when unwrapped. |
| Wrapped functions | callable() returns False; calling the proxy raises TypeError. |
copy.copy, copy.deepcopy, pickle.dumps |
Raise NotImplementedError with the current proxy. |
| Iterability checks | A wrapped integer appears iterable because ObjectProxy defines __iter__; attempting to iterate still fails. |
| Method results / container item access | Can lose the constant marker, so forwarding the result no longer preserves that optimization information. |
Protocol gaps are version- and proxy-class-dependent: wrapt 2.3.0 added conditional AutoObjectProxy.__fspath__ support for targets that implement that protocol. Ordinary strings do not define __fspath__, and this does not resolve identity checks or the regex/string-joining cases.
The final row concerns constant propagation rather than necessarily changing the returned value. The other rows show why support for overriding is alone would not make proxy forwarding transparent.
Upstream research (2026-09-11)
The requested Python hook has a direct predecessor: CPython #36120, hook method for is, opened in 2002 and now closed. Its discussion identifies backwards-compatibility problems for copying and object-graph traversal, plus identity-test overhead. A new Python Ideas discussion should reference that proposal and explain the Citry use case and unresolved constraints, rather than duplicate it as a bug.
wrapt #174 already describes scalar proxies carrying metadata and being rejected by str.join and regex. It is closed; a focused contribution there is preferable to reporting the same behavior again. wrapt #244 separately discusses propagating annotations through results and mentions the is None limitation. wrapt #296 explains selective protocol support and asks for focused issues for remaining concrete requests.
Python and wrapt title/body drafts have been prepared locally for review. Neither has been posted. A Python identity hook alone would not resolve the other compatibility gaps in the table above.
Follow-ups
- Search prior Python and wrapt discussions and prepare upstream title/body drafts for review.
- Review and post the Python Ideas proposal about allowing object methods or a restricted runtime protocol to affect
is/is not, explicitly addressing CPython #36120 and linking the new discussion here. - Review and contribute the wrapt draft to the existing discussion, or open a focused issue if appropriate, covering present transparency limits and possible support if Python introduces a suitable protocol. Link the contribution here.
- Track the other compatibility gaps before restoring forwarding: actual type and identity inspection, built-in consumers of strings and buffers, serialization and copying, callability, iteration, and other special methods.
- Reassess whether upstream capabilities let Citry pass proxies into component methods without changing the behavior of ordinary Python code.
- When those requirements can be met, restore proxy forwarding through custom
template_data()and other component methods, with regressions covering identity checks, representative built-in consumers, and constant-marker preservation through returned values.
Allowing proxy-aware identity comparisons could address singleton and sentinel checks, but would not by itself provide full transparency. This is a future capability to investigate, not a claim that Python or wrapt already supports it.
References: Python identity comparisons, wrapt proxy limitations. Related constant-propagation work: #20.
Activity
[-]Pass ordinary values to component code while preserving constant metadata[/-][+]Restore transparent Const proxy forwarding into component methods when upstream support allows it[/+]