Visitar URL original
Setting locals() value leads to panicked. · Issue #4314 · RustPython/RustPython · GitHub
The Wayback Machine - https://web.archive.org/web/20221229100759/https://github.com/RustPython/RustPython/issues/4314
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting locals() value leads to panicked. #4314

Open
xiaxinmeng opened this issue Dec 8, 2022 · 1 comment
Open

Setting locals() value leads to panicked. #4314

xiaxinmeng opened this issue Dec 8, 2022 · 1 comment

Comments

@xiaxinmeng
Copy link

xiaxinmeng commented Dec 8, 2022

In the following example, we set the locals()[42] as a string "abc" in a class A. Then it causes rustpython panicked.

test.py:


class A(object):
    locals()[42] = 'abc'

Behavior on rustpython(rustpython 0.1.2):

thread 'main' panicked at 'dict has non-string keys: [PyObject PyInt { value: 42 }]', vm/src/builtins/dict.rs:537:48
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected behavior(behavior on CPython 3.9.1):
work well on the Python interpreter

Step to reproduce:
type "cargo run --release test.py" on the console of Ubuntu 18.04 and MacOS Big Sur 11.7.1
rust version: rustc 1.65.0

@DimitrisJim
Copy link
Member

DimitrisJim commented Dec 8, 2022

I honestly was not aware you could update the class __dict__ this way. Another shorter repro is type("A", (), {1:1}) with any other non string key for the dict.

We currently store the class namespace using a map with string keys. Weirdly enough no test cases for CPython test this as far as I could find. I doubt it could be considered an implementation detail, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants