Skip to main content

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

reference

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bypassmappingproxy-0.1.0.tar.gz (1.5 kB view hashes)

Uploaded Source

Built Distribution

bypassmappingproxy-0.1.0-py3-none-any.whl (1.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page