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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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

Hashes for bypassmappingproxy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bfb9fabfd0d97702c75300d119a858c9edeb7de56fde0b323f1a27693caeca62
MD5 38742e7510a9da04fbaba3fcdcf32b6e
BLAKE2b-256 c75113780e21aab0549b0168fd0647a9219c6ecac72c560a3d2a1fc441c8d1b8

See more details on using hashes here.

File details

Details for the file bypassmappingproxy-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for bypassmappingproxy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5387d31e1623398847148739a272e42ea3b92551300c9f29711043e6cfb93373
MD5 3e39bfa92d0f1111cc0ce130941e5de5
BLAKE2b-256 c0d1845e93b5f534000413d62e046adaa45a9fced8a7517ec462deb7ed7d9677

See more details on using hashes here.

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