Skip to main content

Mutable classes of python primitives

Project description

Python Mutable Primitives

While easy to create, it is crazy that python doesn't provide mutable primitives by default (AFAIK).

This package provides some simple python primitive types in a mutable shell:

  • Bool
  • Float
  • Int
  • Str

Basic Usage and Invalid Uses

The safest usage is to always use .set() and .get():

from mutable_primitives import Int

x = Int(5)

def make_x_seven():
    x.set(7)

make_x_seven()

print(x.get()) # should print 7

However if you understand the limitations, you can do some normal operations:

from mutable_primitives import Int
x = Int(5)
print(x + 4) # prints 9 (technically Int(9))
print(4 + x) # prints 9 (technically int(9))
assert x == 5
assert 5 == x

TODO some invalid/bad/dangerous use cases1

Caveats, Reasoning, and FAQ

Q: This whole library is unnecessary.
A: That's a statement.

Q: Why make a library when you can do this in a few lines when needed?
A: Having a library just makes it more uniform and clear what's happening.

Q: There are 4 competing libraries for this functionality, why add another?
A: There are now 5 competing libraries.

Q: Why use obfuscated/unsafe compile/FunctionType when you could just write the functions?
A: I'm lazy, feel free to PR it.

Q: Why not subclass int/float/etc?
A: You can't subclass bool, and subclassing the other primitives brings complexity.

TODO List

In rough order of preference:

  • Proper README.md
  • LICENCE
  • integrate with pypi
  • Tests for Bool class
  • Tests for Int class
  • Tests for Float class
  • Implement Str class
  • Tests for Str class
  • Add thread-safe mutables classes

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

mutable_primitives-0.0.2.tar.gz (2.4 kB view details)

Uploaded Source

File details

Details for the file mutable_primitives-0.0.2.tar.gz.

File metadata

  • Download URL: mutable_primitives-0.0.2.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.1

File hashes

Hashes for mutable_primitives-0.0.2.tar.gz
Algorithm Hash digest
SHA256 93e415ea8791e1bb9e180b9330130014e4224bb5d4c31954e46ce22d812a4410
MD5 158ca5c2f49bca9a0c7a9cdc7fa4a3fc
BLAKE2b-256 be3eb9e6c08faa94765b88996a56b775dab5df49af55824b54ed45007a44b94f

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