GitXplorerGitXplorer
p

maps

public
13 stars
1 forks
3 issues

Commits

List of commits on branch master.
Unverified
23203cdb75037a014862cddfd7ab2772922c1928

no code coverage for indentity mapping function in recurse utility

ppcattori committed 7 years ago
Unverified
6771e379969fdea0e20addeca12de63c65678b25

minor version bump for new `recurse` features

ppcattori committed 7 years ago
Unverified
a0e58041a76499b04ff04f0b5d6046d65db8c642

recurse in docs

ppcattori committed 7 years ago
Unverified
4ca7a2f9e29a16c9be8a52daf78852a0a7ddae55

`None` instead of lambdas for default values

ppcattori committed 7 years ago
Unverified
7b8a7407e6921a15d34e1d290c23dca5d0a5a4d2

no need to implement recurse for metaclasses, as they will get recurse from respective superclasses

ppcattori committed 7 years ago
Unverified
0709d0a49d15cea4f52479da1455b9f305c3ec48

no code coverage for custom object functions in recurse

ppcattori committed 7 years ago

README

The README file for this repository.

PyPI version Build Status Test Code Coverage Compatible Python Versions Documentation Status

maps

Python's missing mappings

Frozen Fixed-key Mutable
bracket access maps.FrozenMap maps.FixedKeyMap dict
dot and bracket access maps.namedfrozen maps.namedfixedkey maps.NamedDict

Install

$ pip install maps

API

Check out the official Maps docs for more!

NamedDict

Just a plain ol' Python dict, but super-charged with access via dot-notation (i.e. __getattr__ and __setattr__).

>>> import maps
>>> d = maps.NamedDict({'a': 1, 'b': 2})
>>> isinstance(d, dict) # drop-in replacement for a `dict`! Can do anything a `dict` can!
True
>>> d.a
1
>>> d.b = 'two'
>>> d
NamedDict({'a': 1, 'b': 'two'})
>>> d.c = 3
>>> d
NamedDict({'a': 1, 'b': 'two', 'c': 3})

namedfrozen

namedfrozen is like namedtuple, but with collections.abc.Mapping under the hood instead of tuple.

In other words, its an immutable mapping with access via bracket-notation (i.e. __getitem__) as well as dot-notation (i.e. __getattr__).

>>> import maps
>>> RGB = maps.namedfrozen('RGB', ['red', 'green', 'blue'])
>>> rgb = RGB(red='rouge', green='forest', blue='azul')
>>> print(rgb)
RGB(red='rouge', green='forest', blue='azul')
>>> rgb['red'] # access via bracket-notation
'rouge'
>>> rgb.green # access via dot-notation
'forest'

namedfixedkey

The namedfixedkey variant is more flexible, allowing edits to existing keys.

>>> import maps
>>> CMYK = maps.namedfixkey('CMYK', ['cyan', 'magenta', 'yellow', 'black'])
>>> cmyk = CMYK(255, 30, 25, 55) # same API as `namedfrozen`, except...
>>> print(cymk)
CMYK(255, 30, 25, 55)
>>> cmyk['magenta'] = 'periwinkle' # overwrite existing items
>>> cmyk.black += 45 # overwrite existing items
>>> print(cmyk)
CMYK(255, 30, 25, 100)