Skip to content
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

unittest: fix no pickle #121

Merged
merged 1 commit into from
Nov 29, 2023
Merged

unittest: fix no pickle #121

merged 1 commit into from
Nov 29, 2023

Conversation

lexdene
Copy link
Contributor

@lexdene lexdene commented Nov 29, 2023

the old NoPickle can be pickled since Python 3.11.
raise error in __getstate__ to fail pickle.

on Python 3.10:

Python 3.10.7 (main, Oct 12 2022, 15:33:27) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> class OldNoPickle(object):
...     def __getattr__(self, name):
...         pass
... 
>>> v1 = OldNoPickle()
>>> pickle.dumps(v1, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable
>>> class NoPickle(object):
...     def __getattr__(self, name):
...         pass
...     def __getstate__(self):
...         raise Exception('can not be pickled')
... 
>>> v2 = NoPickle()
>>> pickle.dumps(v2, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 5, in __getstate__
Exception: can not be pickled

on Python 3.11:

Python 3.11.1 (main, Jan 16 2023, 17:53:09) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> class OldNoPickle(object):
...     def __getattr__(self, name):
...         pass
... 
>>> v1 = OldNoPickle()
>>> pickle.dumps(v1, 2)
b'\x80\x02c__main__\nOldNoPickle\nq\x00)\x81q\x01.'
>>> class NoPickle(object):
...     def __getattr__(self, name):
...         pass
...     def __getstate__(self):
...         raise Exception('can not be pickled')
... 
>>> v2 = NoPickle()
>>> pickle.dumps(v2, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 5, in __getstate__
Exception: can not be pickled

@lexdene lexdene marked this pull request as ready for review November 29, 2023 04:59
@lexdene lexdene requested a review from pypeng November 29, 2023 04:59
@lexdene lexdene merged commit e45ec90 into douban:master Nov 29, 2023
14 of 56 checks passed
@lexdene lexdene deleted the fix_ci branch November 29, 2023 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant