Passing by value in Python functions
Project description
Pass By Value
Passing by value in Python function arguments.
Overview
Python generally implements so called pass by object reference, that is to say, everything in Python is an object and within a function call arguments are mere references to those objects in memory. This is dangerous, because you can modify things without knowing you did. This library allows us to circumvent this behaviour in a simple decorator.
Usage
from pass_by_value import pass_by_value
@pass_by_value
def modify_list(lst):
lst[0] = 'a'
original_list = [1,2,3,4,5]
modified_list = modify_list(original_list)
original_list # [1,2,3,4,5]
modified_list # ['a',2,3,4,5]
Notes
- This library is currently very minimal and relies on
deepcopy
to copy different structures before passing them to functions - Keep in mind that if you are passing a value you are necessarily passing a copy, so if you pass big objects/structures by value you might run out of memory
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
pass_by_value-0.1.0.tar.gz
(3.3 kB
view details)
Built Distribution
File details
Details for the file pass_by_value-0.1.0.tar.gz
.
File metadata
- Download URL: pass_by_value-0.1.0.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7abd716b6c98c5ea7bf5add2d7b2c77e62ceec30f2ec5c21214e72b16d13ddef |
|
MD5 | 120b6968aba4fcff03e871245758f8d1 |
|
BLAKE2b-256 | 0a49dbbad4e6205f5023bee4ada00170a9c907f7d0c33e21b72e76cc33a02342 |
File details
Details for the file pass_by_value-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: pass_by_value-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f554deb23ec75580547b329f71074f776096403120a255e85131b4b3c091e8d9 |
|
MD5 | 2ffb7d4c4c5af94b44df1b33f88109db |
|
BLAKE2b-256 | 253e9e7d3ed72dfa25b7b8715290dbcaa1ba797636b2c69320ded4416ab5aedf |