[issue28250] typing.NamedTuple instances are not picklable Two

2016-09-22 Thread Kurt Dally

New submission from Kurt Dally:

Creating a namedtuple and an instance of the namedtuple in a function then 
returning the instance to the global namespace made the instance unpickleable, 
as in Issue25665.

--
components: Library (Lib)
messages: 277236
nosy: Kurt
priority: normal
severity: normal
status: open
title: typing.NamedTuple instances are not picklable Two
versions: Python 3.5

___
Python tracker 
<http://bugs.python.org/issue28250>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28250] typing.NamedTuple instances are not picklable Two

2016-09-24 Thread Kurt Dally

Kurt Dally added the comment:

My bad, I searched and found the issue, it very closely fit mine and the pickle 
module is new to me.  I hadn't yet got through  the details of  pickling.  
Thanks for catching that.
Kurt

  From: Mark Dickinson 
 To: thedomestic...@yahoo.com 
 Sent: Saturday, September 24, 2016 1:43 AM
 Subject: [issue28250] typing.NamedTuple instances are not picklable Two

Mark Dickinson added the comment:

I don't think this has anything to do with namedtuple; it's true whenever you 
create a class in an inner scope (rather than at module level). This is by 
design, and these restrictions are documented: 
https://docs.python.org/3.6/library/pickle.html#what-can-be-pickled-and-unpickled

For example, running this script:

    import pickle

    def my_func():
        class A:
            pass

        a = A()
        return a

    a = my_func()
    pickle.dumps(a)

produces:

    Traceback (most recent call last):
      File "test.py", line 11, in 
        pickle.dumps(a)
    AttributeError: Can't pickle local object 'my_func..A'

--
nosy: +mark.dickinson
resolution:  -> not a bug
status: open -> closed

___
Python tracker 
<http://bugs.python.org/issue28250>
___

--

___
Python tracker 
<http://bugs.python.org/issue28250>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com