modify immutable types by bypassing mapping proxy
Project description
Modifying sometype.__dict__
You can't directly set an attribute of a builtin type
int.real = 69
TypeError: cannot set 'real' attribute of immutable type 'int'
You also can't modify __dict__
int.__dict__["real"] = 69
TypeError: 'mappingproxy' object does not support item assignment
Mappingproxy provides a read-only proxy for mapping, which prevents modification. However, you can now bypass that using the bypassmappingproxy
module
(it is written in pure python)
from bypassmappingproxy as bmp
assert (1).real == 1
bmp.type_set(int, "real", 69)
assert (1).real == 69
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file bypassmappingproxy-0.1.0.tar.gz
.
File metadata
- Download URL: bypassmappingproxy-0.1.0.tar.gz
- Upload date:
- Size: 1.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfb9fabfd0d97702c75300d119a858c9edeb7de56fde0b323f1a27693caeca62 |
|
MD5 | 38742e7510a9da04fbaba3fcdcf32b6e |
|
BLAKE2b-256 | c75113780e21aab0549b0168fd0647a9219c6ecac72c560a3d2a1fc441c8d1b8 |
File details
Details for the file bypassmappingproxy-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: bypassmappingproxy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 1.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5387d31e1623398847148739a272e42ea3b92551300c9f29711043e6cfb93373 |
|
MD5 | 3e39bfa92d0f1111cc0ce130941e5de5 |
|
BLAKE2b-256 | c0d1845e93b5f534000413d62e046adaa45a9fced8a7517ec462deb7ed7d9677 |