File: README.rst

package info (click to toggle)
python-mergedict 1.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 92 kB
  • sloc: python: 176; makefile: 3
file content (101 lines) | stat: -rw-r--r-- 1,808 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
mergedict - A Python `dict` with a merge() method
===================================================

.. display some badges

.. image:: https://travis-ci.org/schettino72/mergedict.png?branch=master
  :target: https://travis-ci.org/schettino72/mergedict

.. image:: https://coveralls.io/repos/schettino72/mergedict/badge.png
        :target: https://coveralls.io/r/schettino72/mergedict


A MergeDict is a `dict` with a `merge()` method.
`merge()` is like `dict.update()`...

::

    from mergedict import MergeDict

    d1 = MergeDict({'a': 1, 'b': 'one'})
    d1.merge({'a':2, 'c': [2]})

    assert d1 == {'a': 2, 'c': [2], 'b': 'one'}


A MergeDict can be subclassed to create custom "merge" operations
based on the type of an item value.


::

    from mergedict import MergeDict

    class SumDict(MergeDict):
          @MergeDict.dispatch(int)
          def merge_int(this, other):
              return this + other

    d2 = SumDict({'a': 1, 'b': 'one'})
    d2.merge({'a':2, 'b': 'two'})

    assert d2 == {'a': 3, 'b': 'two'}


`mergedict` module comes with a `ConfigDict` that will
extend/update lists/sets/dicts.

::

    from mergedict import ConfigDict

    d3 = ConfigDict({'a': 1, 'my_list': [1, 2]})
    d3.merge({'a':2, 'my_list': [3, 4]})

    assert d3 == {'a': 2, 'my_list': [1, 2, 3, 4]}




Project Details
===============

- Project management on github - https://github.com/schettino72/mergedict/


license
=======

The MIT License
Copyright (c) 2013 Eduardo Naufel Schettino

see LICENSE file


developers / contributors
==========================

- Eduardo Naufel Schettino — main author

- Sebastian Pipping — build system fixes


install
=======

::

 $ pip install mergedict

or download and::

 $ python setup.py install


tests
=======

To run the tests::

  $ py.test