Skip to main content

morecopy

Release Python Downloads DOI Tests

Copy even immutable objects as much as possible

Overview

morecopy is a Python package that enables copy of immutable objects so that a copied object is equivalent but not identical to the original:

from morecopy import copy


original = 1234567890
copied = copy(original)

original == copied # -> True
original is copied # -> False

Note In general, there is no need to copy immutable objects, so this package may not be necessary in most cases. Also, some objects may not be copied even with this package: In CPython, for example, integers from -5 to 256 are always uncopied for optimization.

Installation

$ pip install morecopy

Supported immutable types

The following types are supported. For mutable types (e.g. list) or unsupported immutable types (e.g. bool, NoneType), morecopy.copy and morecopy.deepcopy are equivalent to copy.copy and copy.deepcopy, respectively.

Type morecopy.copy morecopy.deepcopy
int yes n/a
float yes n/a
complex yes n/a
str yes n/a
bytes yes n/a
tuple yes n/a
range yes n/a
slice yes n/a
frozenset yes n/a
FunctionType yes n/a
LambdaType yes n/a

Custom immutable copier

Users can add a custom copy function (copier) for a type. For example, the following code defines copy of integer by creating a copy function and registering it by the copier_for decorator.

from morecopy import copier_for


@copier_for(int)
def copy_int(integer: int) -> int:
    return eval(repr(integer))

Release files for morecopy 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for morecopy 0.4.0
File Size Uploaded
morecopy-0.4.0.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for morecopy 0.4.0
File Interpreter ABI Platform
morecopy-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.9 kB

Release files / morecopy-0.4.0.tar.gz

Download URL morecopy-0.4.0.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b172c26f042e26b629896020ba3cc2698e3c9afcebf195f58e1c96ea4ccf6351
BLAKE2b-256 checksum
How to use checksums
e201856336e76e4476416040190c7aa01f337927a91c5548f7ad856456311390
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.12.0 Linux/6.2.0-1014-azure

Release files / morecopy-0.4.0-py3-none-any.whl

Download URL morecopy-0.4.0-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
094abb95e3b80c8770f2928ac232832959e46af234076d3446282fac39f66e1c
BLAKE2b-256 checksum
How to use checksums
fcf25a6f0a253a5fd2bf9cfcc2b4eda8c6365ef3be675f08891c11a696fda206
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.12.0 Linux/6.2.0-1014-azure

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page