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/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:26443781-684d-e639-2c8b-000acab722e7 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D17C:2D6BC4:2E05A27:3D8FC1E:69705762 |
| html-safe-nonce | 925dcc96d81c6313ae9ba4e3d18be3113b34b51b70088921cbbbd0d7a7a25710 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTdDOjJENkJDNDoyRTA1QTI3OjNEOEZDMUU6Njk3MDU3NjIiLCJ2aXNpdG9yX2lkIjoiODIzMTY2Mzk4NTYzODk5MjM0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e542cf2652faeaf162cdeec2a0034e93a7b8864692a7cf9ee1961cacd1dc17ee |
| hovercard-subject-tag | pull_request:3129383288 |
| 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/6503/files |
| 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 | 9920a62ba22d06470388e2904804fb7e5ec51c9e35f81784e9191394c74b2bd2 |
| 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 | f643964067a552f02067066d6a910b2f90a5721f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width