Skip to content

Preserve importable ModuleType subclass references on CPython - #611

Open
CAOShurong wants to merge 1 commit into
cloudpipe:masterfrom
CAOShurong:codex/397-module-facade-reference
Open

CAOShurong wants to merge 1 commit into
cloudpipe:masterfrom
CAOShurong:codex/397-module-facade-reference

Conversation

@CAOShurong

Copy link
Copy Markdown

Fixes #397.

The module reducer uses exact-type dispatch, so a ModuleType subclass used as a
global can prevent a function from being pickled by value. On CPython, let an
importable subclass with default reduction hooks use the existing module
reference reducer. Exact custom dispatch and custom reduction hooks retain their
precedence, including modules whose custom attribute access must not be inspected.
Unregistered and explicitly by-value subclasses remain unsupported rather than
being flattened into ordinary modules.

Regressions cover protocols 2/4/5, direct modules and function globals, custom
dispatch/hooks, and fresh-process import success and missing-module failure.

Validation on Windows:

  • CPython 3.13.1 full suite twice: 341 passed, 10 skipped, 2 expected xfails.
  • All 278 existing test outcomes unchanged; 75 additional cases pass. On the
    unchanged runtime, the new cases have 9 failures and 66 passes.
  • Focused cases repeated on CPython 3.13.1 and 3.11.16, including non-editable
    wheel installs; the original dump/load reproducer and reducer-control matrix pass.
  • Black, Ruff, wheel/sdist build, Twine, dependency and diff checks pass.

Native ROOT, Dask/Optuna integration, PyPy and other platforms were not tested.

This branch has not been deployed

No deployments
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.

Pickling functions breaks if Python module defined from types.ModuleType is used

1 participant