python-itypes
Port variant py37
Summary Simple immutable types for python (PY37)
Package version 1.2.0
Homepage https://github.com/PavanTatikonda/itypes
Keywords python
Maintainer Python Automaton
License Not yet specified
Other variants py38
Ravenports Buildsheet | History
Ravensource Port Directory | History
Last modified 20 APR 2020, 23:55:49 UTC
Port created 02 FEB 2018, 15:29:04 UTC
Subpackage Descriptions
single # itypes [Build Status] Basic immutable container types for Python. A simple implementation that's designed for simplicity over performance. Use these in circumstances where it may result in more comprehensible code, or when you want to create custom types with restricted, immutable interfaces. For an alternative implementation designed for performance, please see [pyrsistent]. ### Installation Install using `pip`: pip install itypes ### Instantiating dictionaries and lists. >>> import itypes >>> d = itypes.Dict({'a': 1, 'b': 2, 'c': 3}) >>> l = itypes.List(['a', 'b', 'c']) ### On instantiation, nested types are coerced to immutables. >>> d = itypes.Dict({'a': 123, 'b': ['a', 'b', 'c']}) >>> d['b'] List(['a', 'b', 'c']) ### Assignments and deletions return new copies. Methods: `set(key, value)`, `delete(key)` >>> d2 = d.set('c', 456) >>> d2 Dict({'a': 123, 'b': ['a', 'b', 'c'], 'c': 456}) >>> d3 = d2.delete('a') >>> d3 Dict({'b': ['a', 'b', 'c'], 'c': 456}) ### Standard assignments and deletions fail. >>> d['z'] = 123 TypeError: 'Dict' object doesn't support item assignment >>> del(d['c']) TypeError: 'Dict' object doesn't support item deletion ### Nested lookups. Method: `get_in(keys, default=None)` >>> d['b'][-1] 'c' >>> d['b'][5] IndexError: list index out of range >>> d.get_in(['b', -1]) 'c' >>> d.get_in(['b', 5]) None ### Nested assignments and deletions. Methods: `set_in(keys, value)`, `delete_in(keys)` >>> d2 = d.set_in(['b', 1], 'xxx') >>> d2 Dict({'a': 123, 'b': ['a', 'xxx', 'c']}) >>> d3 = d2.delete_in(['b', 0]) >>> d3 Dict({'a': 123, 'b': ['xxx', 'c']}) ### Equality works against standard types. >>> d = itypes.Dict({'a': 1, 'b': 2, 'c': 3}) >>> d == {'a': 1, 'b': 2, 'c': 3} True ### Objects are hashable. >>> hash(d) 277752239 ### Shortcuts for switching between mutable and immutable types. Functions: `to_mutable(instance)`, `to_immutable(value)` >>> value = itypes.to_mutable(d) >>> value {'a': 123, 'b': ['a', 'b', 'c']} >>> itypes.to_immutable(value) Dict({'a': 123, 'b': ['a', 'b', 'c']}) ### Subclassing. Only private attribute names may be set on instances. Use `@property` for attribute access.
Configuration Switches (platform-specific settings discarded)
PY37 ON Build using Python 3.7 PY38 OFF Build using Python 3.8
Package Dependencies by Type
Build and Runtime python37:single:standard
python-setuptools:single:py37
Download groups
main mirror://PYPI/i/itypes
Distribution File Information
af886f129dea4a2a1e3d36595a2d139589e4dd287f5cab0b40e799ee81570ff1 4355 itypes-1.2.0.tar.gz
Ports that require python-itypes:py37
python-coreapi:py37 Python client library for Core API (PY37)