This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Exposes the immutable dictproxy type to all (?) versions of Python.

PEP416 asked for a frozendict type, but was rejected. The alternative was to publicly expose dictproxy, the type used for and immutable object’s __dict__, which wraps an existing dict and provides a read-only interface to it. The type has existed since 2.2, but it’s never had a Python-land constructor.

Until now. But only in 3.3+. Which is not all that helpful to some of us.

This module clumsily exposes the same type to previous versions of Python.

Usage

from dictproxyhack import dictproxy

myproxy = dictproxy(dict(foo="bar"))
print(myproxy['foo'])
myproxy['baz'] = "quux"  # TypeError

Since the proxy holds a reference to the underlying dict (but doesn’t provide any way to get it back), you can trivially implement frozendict:

def frozendict(*args, **kwargs):
    return dictproxy(dict(*args, **kwargs))

Might as well just inline that where you need it, really.

Dependencies

Python. Should work anywhere. Maybe.

On Python 3.3+, you get the real mappingproxy type, which lives in the types module as MappingProxyType.

On CPython 2.5+, you get a fake class that forcibly instantiates dictproxy objects via ctypes shenanigans.

On nearly anything else, you get a regular class that wraps a dict and doesn’t implement any mutating parts of the mapping interface. Not a fabulous solution, but good enough, and only applies until your favorite port catches up with 3.3’s standard library.

On non-C Python ports that predate 2.6, you get pretty much a dict, because the Mapping ABC doesn’t even exist. Sorry.

The shim classes also fool isinstance and issubclass, so your dirty typechecking should work equally poorly anywhere.

I’ve only actually tried this library on CPython 2.6, 2.7, 3.2, 3.3, and PyPy 2.1, but I’m interested in hearing whether it works elsewhere.

Gotchas

Don’t subclass dictproxy. Python 3.3+ won’t let you, and the shims for other versions are of extremely dubious use.

dictproxy has been renamed to mappingproxy in 3.3+, so don’t rely on repr to match across versions or anything. (It seemed apropos to use the older name for this module.)

Release History

Release History

1.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
dictproxyhack-1.1.tar.gz (3.3 kB) Copy SHA256 Checksum SHA256 Source Aug 6, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting