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

pickler: Cython 3.0 compatibility #477

Merged
merged 4 commits into from Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
@@ -1,5 +1,6 @@
v3.0.3
======
* Compatibilty with Pandas and Cython 3.0 was added. (#460) (+477)
* Fixed a bug where pickling some built-in classes (e.g. zoneinfo)
could return a ``None`` module. (#447)
* Fixed a bug where unpickling a missing class would return a different object
Expand Down
6 changes: 3 additions & 3 deletions jsonpickle/pickler.py
Expand Up @@ -803,15 +803,15 @@ def _get_flattener(self, obj):
else tags.SET: [self._flatten(v) for v in obj]
}

elif util.is_module_function(obj):
return self._flatten_function

elif util.is_object(obj):
return self._ref_obj_instance

elif util.is_type(obj):
return _mktyperef

elif util.is_module_function(obj):
return self._flatten_function

# instance methods, lambdas, old style classes...
self._pickle_warning(obj)
return None
Expand Down
11 changes: 10 additions & 1 deletion jsonpickle/util.py
Expand Up @@ -301,7 +301,7 @@ def is_module_function(obj):
and hasattr(obj, '__module__')
and hasattr(obj, '__name__')
and obj.__name__ != '<lambda>'
)
) or is_cython_function(obj)


def is_module(obj):
Expand Down Expand Up @@ -388,6 +388,15 @@ def is_reducible(obj):
return True


def is_cython_function(obj):
"""Returns true if the object is a reference to a Cython function"""
return (
callable(obj)
and hasattr(obj, '__repr__')
and repr(obj).startswith('<cyfunction ')
)


def in_dict(obj, key, default=False):
"""
Returns true if key exists in obj.__dict__; false if not in.
Expand Down