Author ddddaaaa
Recipients belopolsky, ddddaaaa, p-ganssle
Date 2020-10-08.06:34:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1602138862.72.0.264522912451.issue41966@roundup.psfhosted.org>
In-reply-to
Content
Code demonstrating the issue; the CTimeFoo class is pickled correctly, but TimeFoo isn't.


import builtins
from _datetime import time as ctime

original_importer = builtins.__import__

def my_importer(name, globals, locals, fromlist, level):
    if name == '_datetime':
        raise ImportError

    return original_importer(name, globals, locals, fromlist, level)

builtins.__import__ = my_importer

import datetime

builtins.__import__ = original_importer

import pickle


class CTimeFoo(ctime): pass
class TimeFoo(datetime.time): pass
class DateFoo(datetime.date): pass


if __name__ == "__main__":
    t = DateFoo(2001, 2, 3) 
    d = pickle.dumps(t)  # OK
    print(d)
    # b'\x80\x04\x95#\x00\x00\x00\x00\x00\x00\x00\x8c\x08__main__\x94\x8c\x07DateFoo\x94\x93\x94C\x04\x07\xd1\x02\x03\x94\x85\x94R\x94.'
    t = pickle.loads(d)

    t = CTimeFoo(1, 2, 3)  
    d = pickle.dumps(t)  # OK
    print(d)
    # b'\x80\x04\x95&\x00\x00\x00\x00\x00\x00\x00\x8c\x08__main__\x94\x8c\x08CTimeFoo\x94\x93\x94C\x06\x01\x02\x03\x00\x00\x00\x94\x85\x94R\x94.'
    t = pickle.loads(d)

    t = TimeFoo(1, 2, 3)
    d = pickle.dumps(t)  # :(
    print(d)
    # b'\x80\x04\x95"\x00\x00\x00\x00\x00\x00\x00\x8c\x08datetime\x94\x8c\x04time\x94\x93\x94C\x06\x01\x02\x03\x00\x00\x00\x94\x85\x94R\x94.'
    t = pickle.loads(d)
History
Date User Action Args
2020-10-08 06:34:22ddddaaaasetrecipients: + ddddaaaa, belopolsky, p-ganssle
2020-10-08 06:34:22ddddaaaasetmessageid: <1602138862.72.0.264522912451.issue41966@roundup.psfhosted.org>
2020-10-08 06:34:22ddddaaaalinkissue41966 messages
2020-10-08 06:34:21ddddaaaacreate