-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
datetime.time issue with pickling in PyPy #86132
Comments
I've run into an issue pickling a datetime.time subclass in PyPy3. I believe it arises because PyPy uses the pure Python implementation of time and time.__reduce_ex__() returns (time, ...) on this line ( Line 1551 in 044a104
|
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: