Jason R. Coombs <jar...@jaraco.com> added the comment:

I've encountered a use-case where the need to pickle NoneType is more relevant 
(and difficult to work around).

We have a strongly-type Limited Python language, LimPy, which is based on 
Python (https://bitbucket.org/yougov/limpy). This parser takes, as part of its 
initialization arguments, a type specification (indicating which types are 
allowed and not allowed). In some cases, the return value may be `None`, in 
which case the specification says the type must be `NoneType`.

We're attempting to run this parser in a separate process, using the 
multiprocessing module, which requires that the arguments passed to and from 
the parser be pickleable. Unfortunately, because `NoneType` is in the type 
specification, it cannot be passed to the parser.

Here's an example of one such type specification (from the test suite):

    class SomeFunctionNamespace:
        @signature([IListType], [], None, ListOfInt)
        def listcount(self, l):
            return range(len(l))

        @signature([IListType], [], None, int)
        def listlen(self, l):
            return len(l)

        # ...

        @signature([IIntType], [IStringType], IStringType, NoneType)
        def givespec(self, *args):
            for a in args:
                print a


Note that we can pickle `str` and `int` just fine. Only type(None) fails.

It would be possible to re-write the entire LimPy system (and its child 
projects) to use a different object where currently NoneType is used, though 
NoneType is precisely the right thing to be used here except that it can't be 
pickled.

Since type(None) is a fundamental Python type, it strikes me as a bug that it's 
not pickleable, though I concede that it's also reasonable to interpret this 
issue as a feature request (as it's never been pickleable).

Nick makes some good comments that pickling of NoneType should be done right, 
but other than that, there haven't been any reasons why in principle NoneType 
should not be pickleable.

NoneType is more akin to `str` and `int` which are pickleable than it is to a 
function or type(NotImplemented), and this is evident by the way that LimPy 
uses it (before there was any consideration for pickleability).

Therefore, I propose we reconsider that NoneType should be made pickleable.

----------
nosy: +jaraco

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue6477>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to