Title: Handle non-string keys in class namespaces without panicking by Copilot · Pull Request #6503 · RustPython/RustPython · GitHub
Open Graph Title: Handle non-string keys in class namespaces without panicking by Copilot · Pull Request #6503 · RustPython/RustPython
X Title: Handle non-string keys in class namespaces without panicking by Copilot · Pull Request #6503 · RustPython/RustPython
Description: Setting non-string keys in a class namespace (e.g., via locals()[42] = "abc") caused RustPython to panic; mappingproxy also ignored such entries.
Class namespace handling
Split string attributes from non-string entries when building types; keep non-string entries in a side dict to avoid panics.
Expose combined view via __dict__/mappingproxy so non-string keys are still reachable.
Mappingproxy behavior
Allow lookup, containment, and copy over the preserved non-string namespace entries.
Error messaging
dict.to_attributes now raises a clear TypeError for non-string attribute keys.
Regression coverage
Added snippet ensuring locals()[42] in a class ends up accessible via __dict__.
Example:
class B(object):
locals()[42] = "abc"
assert B.__dict__[42] == "abc"
Original prompt
This section details on the original issue you should resolve
Open Graph Description: Setting non-string keys in a class namespace (e.g., via locals()[42] = "abc") caused RustPython to panic; mappingproxy also ignored such entries. Class namespace handling Split string ...
X Description: Setting non-string keys in a class namespace (e.g., via locals()[42] = "abc") caused RustPython to panic; mappingproxy also ignored such entries. Class namespace handling Split...
Opengraph URL: https://github.com/RustPython/RustPython/pull/6503
X: @github
Domain: patch-diff.githubusercontent.com
| route-pattern | /:user_id/:repository/pull/:id/checks(.:format) |
| route-controller | pull_requests |
| route-action | checks |
| fetch-nonce | v2:f3748035-335e-8a27-d74c-79fd7203edad |
| current-catalog-service-hash | 87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a |
| request-id | 8260:28EEF5:6F8406:9A6C57:696FE5AC |
| html-safe-nonce | b71d7f4ae030bd2db9a39296534ee1d0bb91ca997c605df9b8042c902f9326a1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MjYwOjI4RUVGNTo2Rjg0MDY6OUE2QzU3OjY5NkZFNUFDIiwidmlzaXRvcl9pZCI6IjYyMDQwOTUyODQ2MzY1NDIzODAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3509b117c79f2b1b5d5752f641832db1f438f077e45c55e6bd0da8a5e25cf561 |
| hovercard-subject-tag | pull_request:3129383288 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,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/6503/checks |
| twitter:image | https://avatars.githubusercontent.com/in/1143301?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/in/1143301?s=400&v=4 |
| og:image:alt | Setting non-string keys in a class namespace (e.g., via locals()[42] = "abc") caused RustPython to panic; mappingproxy also ignored such entries. Class namespace handling Split string ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | bb7c872aa74896d911608183f4997f8b9c121a1624064705ec4570cd91bd7839 |
| turbo-cache-control | no-preview |
| 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 full-width-p-0 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 257e1b418957178bd3ac9f7520608a40ebbb0f1e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width