[Python-ideas] Adding "Typed" collections/iterators to Python

Nick Coghlan ncoghlan at gmail.com
Mon Dec 19 06:44:52 CET 2011


On Mon, Dec 19, 2011 at 2:47 PM, Nathan Rice
<nathan.alexander.rice at gmail.com> wrote:
> Regardless, I'm sure everything that gets added to the
> language was first a hugely popular PyPI project, that is clearly the
> way the language evolves.

Not everything, no. The real criteria is to have solid use cases where
a proposal clearly improves the language. Sometimes that's just
obvious (e.g. supporting a popular new compression protocol),
sometimes a PEP is enough to explain, other times real world
experience on PyPI is the best option. You don't have *any* of those
at this point (just some vague hand-waving), so publishing a PyPI
package is the most obvious way to start acquiring more data (and to
prove that there's even a version of the idea that can be taken beyond
the hand-waving stage).

What you seem to be asking for is a general purpose typed container
factory along the following lines:

    def typed_container(container_type, data_type):
        class TypedContainer(container_type):
            def __getattr__(self, attr):
                data_type_attr = getattribute(data_type, attr)
                if callable(data_type_attr):
                    _result_type = type(self)
                    def _broadcast(*args, **kwds):
                        _result_type(data_type_attr(x, *args, **kwds)
for x in self)
                    return _broadcast
                return data_type_attr
        return TypedContainer

I think it will have a lot of problems in practice (note that NumPy
doesn't try to solve the broadcasting problem in general, just for a
single specific data type), but, if the concept has any merit at all,
that's certainly something that can be demonstrated quite adequately
on PyPI.

To get a better idea of the level of evidence you're trying to reach
if your suggestion is ever going to get anywhere, try taking a look at
http://www.boredomandlaziness.org/2011/02/justifying-python-language-changes.html
and http://www.boredomandlaziness.org/2011/02/status-quo-wins-stalemate.html.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list