Skip to main content

A collection of super mutables

Project description

This project defines two kinds of mutables.

dot

The dot module contains classes that allow dot-notation to be used for when accessing a list or dict object.

eg:

>>  from supermutes.dot import dotify
>>  d = dotify({'a':[1, 2, 3, 4, 5], 'b': {'c': 5}})
>>  d.a._0
1
>>  d.b.c
5
>>  d.c = {'f': 9}
>>  d.c.f
9

readonly

The readonly module contains classes that transform dict and list objects into ones that cannot have any values changed on them.

eg:

>>  from supermutes.readonly import readonly
>>  r = readonly({'a':[1, 2, 3, 4, 5], 'b': {'c': 5}})
>>  r
{'a': [1, 2, 3, 4, 5], 'b': {'c': 5}}
>>  r['a'].append(5)
supermutes.readonly.ReadOnlyClassException: Cannot write to object.
>> r['b']['d'] = 6
supermutes.readonly.ReadOnlyClassException: Cannot write to object.

Creating Sub Classes

Upon declaration of a sub class of any of the supermutes, that class will be set as the defacto class for recursively changing data sets.

To reset the classes back to the original set, use the reset_mapping method inside the module

eg:

>>> from supermutes.dot import DotDict, DotList, reset_mapping
>>> class MySubClass(DotDict): pass
>>> d = MySubClass({'a': {'b': {'c': 3}}})
>>> d.a.b
{'c': 3}
>>> d.a.b.__class__
<class '__main__.MySubClass'>
>>> f = DotList([1, {}])
>>> f[1].__class__
<class '__main__.MySubClass'>
>>> reset_mapping()
>>> f = DotList([1, {}])
>>> f[1].__class__
<class 'supermutes.dot.DotDict'>

Writing your own Supermutable

If you would like to contribute, and write a supermutable that behaves in a particular fashion, just try to follow these guidelines:

  • It should inherit from the mutable type that it is adapting (eg dict list etc.)

  • It should also inherit from base.SuperMutable. This takes care of all of the registering of any subclasses so that for example, all sub dicts added to the SuperMutable are changed accordingly. See example.py for a working sample.

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

supermutes-0.2.1.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file supermutes-0.2.1.tar.gz.

File metadata

  • Download URL: supermutes-0.2.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for supermutes-0.2.1.tar.gz
Algorithm Hash digest
SHA256 38240659711d79c4968886ffb32b259202b83d8810530d2c581655d563fd810a
MD5 49950c61dc801714969df558313319ec
BLAKE2b-256 939938801b1ac81de2b51a4ff89abac581288ac72cf7fd587662745c6814e65e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page