Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

morecopy

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

morecopy

Copy even immutable objects as much as possible

  • 0.4.0
  • PyPI
  • Socket score

Maintainers
1

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.

Typemorecopy.copymorecopy.deepcopy
intyesn/a
floatyesn/a
complexyesn/a
stryesn/a
bytesyesn/a
tupleyesn/a
rangeyesn/a
sliceyesn/a
frozensetyesn/a
FunctionTypeyesn/a
LambdaTypeyesn/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))

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc