Created
July 24, 2018 15:28
-
-
Save ncoghlan/0f7727d7a32114899b18b963ce172322 to your computer and use it in GitHub Desktop.
API renames, aliasing, and cross-version pickle compatibility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> class C: | |
... def example(self): pass | |
... | |
>>> import pickle | |
>>> data = pickle.dumps(C.example) | |
>>> pickle.loads(C.example) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
TypeError: a bytes-like object is required, not 'function' | |
>>> pickle.loads(data) | |
<function C.example at 0x7f2fb7786048> | |
>>> del C.example # Pretend we're sending to an old version with no "example" method | |
>>> pickle.loads(data) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
AttributeError: type object 'C' has no attribute 'example' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The reason this is annoying when it comes to API renames is that you have to choose between the following undesirable options:
Bonus level: if you ever want to actually deprecate and remove the old name, you don't even get to start that process until after adopting option 2 above :)