Title: Align namespace, super and dictionary controls by youknowdot · Pull Request #9708 · RustPython/RustPython · GitHub
Open Graph Title: Align namespace, super and dictionary controls by youknowdot · Pull Request #9708 · RustPython/RustPython
X Title: Align namespace, super and dictionary controls by youknowdot · Pull Request #9708 · RustPython/RustPython
Description: Summary Group namespace, mapping-proxy, super lookup and dictionary lookup/iterator controls for Python 3.15 in six Rust source files (+441/-456). SimpleNamespace Convert non-exact dictionary inputs through the normal mapping protocol, validate all keys before mutation, and write instance dictionaries directly rather than invoking attribute setters/descriptors. Accept any SimpleNamespace subtype returned by replacement construction, retain its fields, and apply replacement keywords directly. Snapshot repr keys while looking up live values, reuse dictionary hash-error handling, and release snapshot owners backwards under the recursion guard on both success and error. Remove weak-reference support from the exact base while retaining normal subclass behavior. Mapping proxies and shared dictionary lookup Route containment through fallible mapping controls, propagating hash/equality failures rather than panicking. Native namespace fallback lookups also honor dictionary key callbacks. Delegate union and str to the underlying mappings, preserve arbitrary callback results, accept the named mapping constructor argument, and correct inplace-union diagnostics. Keep dictionary-backed class views and iterators attached to the actual namespace; copy remains a separate operation. Preserve #9128's defensive exact-dict copy for unknown comparison peers and #9039's raw comparison results. Revalidate shared read probes after equality and temporary-key finalizers. Check the current table and candidate before using its entry, restart invalid probes, and extract values under the validated read guard. Do not retain earlier rejected keys or introduce a second per-method probe algorithm. Make cached dictionary hints identity-only, avoiding unrelated key equality and stale values. Reuse the same validated lookup extraction for refreshed hints, so values are cloned before releasing the read guard. Dictionary iterators Share checked state and stepping across keys, values and items in both directions, including reduction snapshots that do not advance or poison the original iterator. Track live remaining elements instead of physical slots, allowing ordinary same-used key replacement while retaining private relocation safeguards. Distinguish sticky size failures from terminal excess-key failures. Clone only projected references under the dictionary/iterator guards, then allocate tuples/errors and release detached dictionary owners outside those guards. Existing set iteration checks remain unchanged. Super namespace lookup Share fallible class-namespace lookup with mapping proxies. Preserve the original query object for heap dictionaries and string-subclass keys, propagate hash/equality errors, and find fresh names inserted into live class dictionaries. Exact-string native lookups retain their map fast path. Snapshot the MRO and release its read lock before dictionary callbacks, then release the owned snapshot before descriptor dispatch or generic fallback. Descriptor owner and instance arguments remain unchanged. Use optional obj.__class__ lookup, correct the missing zero-argument class-cell exception, preserve native type-name prefixes and 200-byte diagnostics, and reject keywords before positional binding through a small preflight around the existing argument binder. Validation Compared against CPython d220409a13b77de7a6c30abe16ea90db01528edc namespaceobject.c, descrobject.c and dictobject.c. External CPython 3.15.0 namespace oracle and independent review passed, including hash callbacks, mutations, rejected mappings, subtype replacement, and finalizer reentry on success/error. Mappingproxy oracle: 94 controls passed. Shared dictionary oracle: 38 controls passed, including deletion, replacement at recycled coordinates, table resize, live value updates, finalizer-before-retry and exception traceback owners. Dedicated independent core review checked probe lifetimes and table validation separately. Ten additional isolated attribute-read oracle groups passed: wrong-hash callbacks are skipped, and key/value mutation, removal, replacement, resize, errors and finalizer reentry produce the current result. Independent hinted-read ownership/lock review passed on the final patch. Dictionary iterator reference coverage: 159 candidate-focused assertions plus 90 independent ownership/reentry assertions passed. Independent source review checked state snapshots, terminal transitions, dictionary ownership, lock scopes and GC traversal. Super reference coverage: 43 original controls, 12 focused diagnostic checks and 48 independent checks passed pinned CPython. Independent source review covered error identity, query controls, namespace/MRO ownership, lock scopes, descriptors, subclass initializers and documented native-snapshot limitations. These are reference results, not native RustPython runtime results. Final composed threaded cargo check passed (1m02s), all-targets Clippy passed (2m09s), and normal commit hooks passed. All twelve baseline diagnostics in host_env/socket, VM POSIX and ElementTree are unchanged; no suppression was added. Limits Native RustPython execution remains unperformed because the required safety guard is not verified. One existing Rust unit-test invocation is mechanically adjusted for the now-infallible hint API; its assertion and expected value are unchanged. No Python tests, test markers, or workflows were modified. Hosted runtime CI remains necessary. Attributes-backed native namespaces still require materialized snapshots. This includes mutable AST namespace views, callbacks changing those namespaces, and union-exposed backing-dictionary identity. Only actual dictionary-backed class namespaces become live; no type-storage redesign is included. For super lookups with callback-bearing queries, a native AST namespace mutation can still leave the materialized snapshot stale and postpone destruction of replaced values. The native exact-string fast path has no Python key callbacks. The read-probe correction uses allocation identity like CPython, not a new mutation-history counter. Same-key clear/reinsert callback counts can depend on allocator reuse; no universal count claim is made for that case. Hinted reads are included; concurrent races after separate mutation lookup/commit phases, including pop/remove_if, remain outside this patch. No broad operation-atomicity or native stress-test claim is made. Existing module-qualification differences in SimpleNamespace replacement rejection diagnostics are also unchanged. Integration: #9681's separate reentrant LRU mutation helpers are unchanged and must remain on composition. Older #6215 instead raises on changed dictionary size; this patch follows CPython restart semantics rather than adopting that behavior. Broad ownership work in #8944/#8939 may require textual reconciliation. Those PRs already include an owned super MRO snapshot; preserve that change when composing. They do not supply the fallible raw namespace/query controls added here. Dictionary iterator limitations: private relocation guards remain conservative for internal compaction. Cached item-result tuple ownership/identity and view-intersection error cleanup remain separately identified follow-ups; this patch does not mutate published tuples or claim those fixes. No concurrent stress/benchmark pass is claimed. Ownership integration detail: #8939/#8944 create AST classes as interpreter-local heap types with real dictionaries. That should remove the specific AST snapshot gap when combined with this lookup helper, but this conclusion is source-only. The new owned dictionary accessor must resolve their interpreter-local namespace before returning it; shared native runtime namespaces should use a real interpreter-owned dictionary. Preserve bootstrap Attributes, stable native identities and registry initialization/GC ordering. Do not attach a runtime dictionary to a process-global native definition or keep a second value-owning Attributes mirror. This integration has not been implemented or compiled in this PR.
Open Graph Description: Summary Group namespace, mapping-proxy, super lookup and dictionary lookup/iterator controls for Python 3.15 in six Rust source files (+441/-456). SimpleNamespace Convert non-exact dictionary inpu...
X Description: Summary Group namespace, mapping-proxy, super lookup and dictionary lookup/iterator controls for Python 3.15 in six Rust source files (+441/-456). SimpleNamespace Convert non-exact dictionary inpu...
Opengraph URL: https://github.com/RustPython/RustPython/pull/9708
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:106db452-d4b4-1cfc-6c0b-973566ab939d |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | CB10:4D9F2:1374DC4:19DF1BD:6B01F3A2 |
| html-safe-nonce | c1ec1869bc9b622855e75c3ae2e903ef7332e589a198610ee26e9f9671da26e7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjEwOjREOUYyOjEzNzREQzQ6MTlERjFCRDo2QjAxRjNBMiIsInZpc2l0b3JfaWQiOiI0NzQxNTg1Mjc4ODY1NjM0MjEwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | bf2b28caaf7a6cb662923328d7bfeb8bf358e770581613888facc406d012d684 |
| hovercard-subject-tag | pull_request:5156059615 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/RustPython/RustPython/pull/9708/files |
| twitter:image | https://avatars.githubusercontent.com/u/336763669?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/336763669?s=400&v=4 |
| og:image:alt | Summary Group namespace, mapping-proxy, super lookup and dictionary lookup/iterator controls for Python 3.15 in six Rust source files (+441/-456). SimpleNamespace Convert non-exact dictionary inpu... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git |
| octolytics-dimension-user_id | 39710557 |
| octolytics-dimension-user_login | RustPython |
| octolytics-dimension-repository_id | 135201145 |
| octolytics-dimension-repository_nwo | RustPython/RustPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 135201145 |
| octolytics-dimension-repository_network_root_nwo | RustPython/RustPython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width