Skip to main content

No project description provided

Project description

ContextManaged Assign

This Python project provides a context manager for temporarily assigning a value to a variable or attribute. The original value is restored when the context is exited.

Usage

from contextmanaged_assign import assign

l = [1, 2, 3]

assert l[0] == 1
with assign("l[0]", 2):
    assert l[0] == 2
assert l[0] == 1

Please note that assign cannot modify local variables themselves. For example, the following code will not work:

x = 1
with assign("x", 2):
    assert x == 2  # AssertionError: 1 != 2
assert x == 1

Installation

Simply install the package using pip:

pip install contextmanaged-assign

Then import the assign function from the contextmanaged-assign module.

License

MIT

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

contextmanaged_assign-0.1.0.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

contextmanaged_assign-0.1.0-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file contextmanaged_assign-0.1.0.tar.gz.

File metadata

  • Download URL: contextmanaged_assign-0.1.0.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for contextmanaged_assign-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2fb048178836a43313976d9f48d7e444b4d792fa0e1ce6950060419135c7cc1e
MD5 160ca0b18c0a9c156a861d973cda4bbb
BLAKE2b-256 73eee6b504910b1ed5df9363492f8bb85ae6f0689da152372542decaa9334f1c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for contextmanaged_assign-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e12a26bbe0501dc4b498925dc2bc8b58fcd78fab0e3de1e8b75d822f6683866
MD5 ed0f068ee15339d54e212eb817133777
BLAKE2b-256 183886961657f6c95c41fab88103872bf86b38b7d6bf49d39fe7533152865b4e

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