# morecopy
[![Release](https://img.shields.io/pypi/v/morecopy?label=Release&color=cornflowerblue&style=flat-square)](https://pypi.org/project/morecopy/)
[![Python](https://img.shields.io/pypi/pyversions/morecopy?label=Python&color=cornflowerblue&style=flat-square)](https://pypi.org/project/morecopy/)
[![Downloads](https://img.shields.io/pypi/dm/morecopy?label=Downloads&color=cornflowerblue&style=flat-square)](https://pepy.tech/project/morecopy)
[![DOI](https://img.shields.io/badge/DOI-10.5281/zenodo.5594444-cornflowerblue?style=flat-square)](https://doi.org/10.5281/zenodo.5594444)
[![Tests](https://img.shields.io/github/actions/workflow/status/astropenguin/morecopy/tests.yml?label=Tests&style=flat-square)](https://github.com/astropenguin/morecopy/actions)
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:
```python
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
```shell
$ 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.
```python
from morecopy import copier_for
@copier_for(int)
def copy_int(integer: int) -> int:
return eval(repr(integer))
```
Raw data
{
"_id": null,
"home_page": "https://github.com/astropenguin/morecopy/",
"name": "morecopy",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<3.13",
"maintainer_email": "",
"keywords": "copy,deepcopy",
"author": "Akio Taniguchi",
"author_email": "taniguchi@a.phys.nagoya-u.ac.jp",
"download_url": "https://files.pythonhosted.org/packages/e2/01/856336e76e4476416040190c7aa01f337927a91c5548f7ad856456311390/morecopy-0.4.0.tar.gz",
"platform": null,
"description": "# morecopy\n\n[![Release](https://img.shields.io/pypi/v/morecopy?label=Release&color=cornflowerblue&style=flat-square)](https://pypi.org/project/morecopy/)\n[![Python](https://img.shields.io/pypi/pyversions/morecopy?label=Python&color=cornflowerblue&style=flat-square)](https://pypi.org/project/morecopy/)\n[![Downloads](https://img.shields.io/pypi/dm/morecopy?label=Downloads&color=cornflowerblue&style=flat-square)](https://pepy.tech/project/morecopy)\n[![DOI](https://img.shields.io/badge/DOI-10.5281/zenodo.5594444-cornflowerblue?style=flat-square)](https://doi.org/10.5281/zenodo.5594444)\n[![Tests](https://img.shields.io/github/actions/workflow/status/astropenguin/morecopy/tests.yml?label=Tests&style=flat-square)](https://github.com/astropenguin/morecopy/actions)\n\nCopy even immutable objects as much as possible\n\n## Overview\n\nmorecopy is a Python package that enables copy of immutable objects so that a copied object is equivalent but not identical to the original:\n\n```python\nfrom morecopy import copy\n\n\noriginal = 1234567890\ncopied = copy(original)\n\noriginal == copied # -> True\noriginal is copied # -> False\n```\n\n> **Note**\n> In general, there is no need to copy immutable objects, so this package may not be necessary in most cases.\n> Also, some objects may not be copied even with this package:\n> In CPython, for example, integers from -5 to 256 are always uncopied for optimization.\n\n## Installation\n\n```shell\n$ pip install morecopy\n```\n\n## Supported immutable types\n\nThe following types are supported.\nFor 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.\n\nType | `morecopy.copy` | `morecopy.deepcopy`\n--- | --- | ---\n`int` | yes | n/a\n`float` | yes | n/a\n`complex` | yes | n/a\n`str` | yes | n/a\n`bytes` | yes | n/a\n`tuple` | yes | n/a\n`range` | yes | n/a\n`slice` | yes | n/a\n`frozenset` | yes | n/a\n`FunctionType` | yes | n/a\n`LambdaType` | yes | n/a\n\n## Custom immutable copier\n\nUsers can add a custom copy function (copier) for a type.\nFor example, the following code defines copy of integer by creating a copy function and registering it by the `copier_for` decorator.\n\n```python\nfrom morecopy import copier_for\n\n\n@copier_for(int)\ndef copy_int(integer: int) -> int:\n return eval(repr(integer))\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Copy even immutable objects as much as possible",
"version": "0.4.0",
"project_urls": {
"Homepage": "https://github.com/astropenguin/morecopy/"
},
"split_keywords": [
"copy",
"deepcopy"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fcf25a6f0a253a5fd2bf9cfcc2b4eda8c6365ef3be675f08891c11a696fda206",
"md5": "8bd3f1019f09e94412c1187a4fc40bea",
"sha256": "094abb95e3b80c8770f2928ac232832959e46af234076d3446282fac39f66e1c"
},
"downloads": -1,
"filename": "morecopy-0.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8bd3f1019f09e94412c1187a4fc40bea",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<3.13",
"size": 4487,
"upload_time": "2023-10-19T11:35:14",
"upload_time_iso_8601": "2023-10-19T11:35:14.082727Z",
"url": "https://files.pythonhosted.org/packages/fc/f2/5a6f0a253a5fd2bf9cfcc2b4eda8c6365ef3be675f08891c11a696fda206/morecopy-0.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e201856336e76e4476416040190c7aa01f337927a91c5548f7ad856456311390",
"md5": "7842efee8eebd2d7a4495b5dc03ab51e",
"sha256": "b172c26f042e26b629896020ba3cc2698e3c9afcebf195f58e1c96ea4ccf6351"
},
"downloads": -1,
"filename": "morecopy-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "7842efee8eebd2d7a4495b5dc03ab51e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<3.13",
"size": 3461,
"upload_time": "2023-10-19T11:35:15",
"upload_time_iso_8601": "2023-10-19T11:35:15.576438Z",
"url": "https://files.pythonhosted.org/packages/e2/01/856336e76e4476416040190c7aa01f337927a91c5548f7ad856456311390/morecopy-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-19 11:35:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "astropenguin",
"github_project": "morecopy",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "morecopy"
}