Skip to main content

Mutable classes of python primitives

Project description

Python Mutable Primitives

Test Status Coverage Status PyPI - Python Version PyPI - License

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 cases

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 write out so many repetitive functions when you could just inherit?
A: So that test coverage can be sure that it's run. Also the code is generated and committed, so it's not extra dev effort.

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:

  • Better README.md
  • Ensure correct type used with .set(), e.g. x = Int(5); x.set('bad') should error
  • 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.7.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

mutable_primitives-0.0.7-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mutable_primitives-0.0.7.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for mutable_primitives-0.0.7.tar.gz
Algorithm Hash digest
SHA256 f9005b845eb8472a334e7100ec025e44b0272edf829b41013cd226821ec59bc1
MD5 b2ec66493acc5654c6446f7a58bf5137
BLAKE2b-256 ea14688a5f71f641b8ec762a467887426b41d4a05bcd1840ba13a9f805005651

See more details on using hashes here.

File details

Details for the file mutable_primitives-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for mutable_primitives-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 4ef2cdbde19b285058904d53ef07e24ea9e7021731f6d4384e8d7bb523b2bc54
MD5 82043d4fc542f75ff272c66b470677af
BLAKE2b-256 a2537de195132c15c02c79dc45e1b14dcba59262f229805d096204b1155d5138

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