andy-maier / immutable-views Goto Github PK
View Code? Open in Web Editor NEWImmutable views on other collection objects
License: Apache License 2.0
Immutable views on other collection objects
License: Apache License 2.0
This would be for encoding DictView and ListView objects into JSON.
For decoding, this would probably not be interesting.
In case the view classes are used on hashable collections (e.g. frozenset, any of the immutable collection classes on Pypi, nocasedict with the limited hashing support, etc), they should support the __hash__()
method and delegate that to the underlying collection, leaving it to that collection to reject the call.
Also, test code should be added that verifies the rejection for non-hashable underlying collections and the success for hashable underlying collections.
Finally, this topic deserves a short section in the docs.
Places in test code that access protected attributes of the View objects:
TBD: What about test DictView()?
test_dict_view.py:1496/1501 - test DictView.copy()
test_list_view.py:230/238 - test ListView()
test_list_view.py:1782/1787 - test ListView.copy()
test_set_view.py:203/210 - test SetView()
test_set_view.py:3334/3339 - test SetView.copy()
This is a copy&paste error and needs to be fixed.
In Python 3.9, two new operator methods have been added to ´dict`:
def __or__(self)
- used in self | other
def __ior__(self)
- used in self |= other
PR #9 implements SetView, but tests still need to be written.
Some facts on types.MappingProxyType
(as of Python 3.9):
SetView and ListView already has them.
I really like the idea of this library. I could not find any other libraries that provide the same functionality, and I think this is a valuable and somehow unused contribution to the community. However, to provide the same user experience as if using the collections themselves, I think type annotations should be provided. I will try and pick that up, and, if welcome, make a PR some time later.
Class DictView
currently inherits from abstract class Mapping
, but implements the read-only functions of dict
which provides some more functions than those of Mapping
, so inheriting from dict
would be nice, also from a perspective that this would allow using DictView
objects where dict
objects are declared and checked. On the other hand, DictView
does not implement the modifying methods of dict
, and inheriting from dict
is a statement that it does support all of its methods.
Ditto for ListView
, it implements read-only methods from list
but inherits from Sequence
.
Clarify whether the inheritance should be changed.
Asked the question on the python-list mailing list: https://mail.python.org/pipermail/python-list/2021-April/901876.html
The SetView class has the latest level of documentation.
Update the documentation of the ListView and DictView classes to match that of SetView.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.