Skip to content

Fix pickeling - #717

Open
Vizonex wants to merge 21 commits into
aio-libs:masterfrom
Vizonex:fix-pickeling
Open

Vizonex wants to merge 21 commits into
aio-libs:masterfrom
Vizonex:fix-pickeling

Conversation

@Vizonex

@Vizonex Vizonex commented Nov 6, 2025 •

Copy link
Copy Markdown
Member

What do these changes do?

I forgot I had made a fork for trying to fix pickling but I seemed to never bother to add it after the issuer told me there was no need but it seems it needs to come back. This PR adds in a new argument to freeze a frozenlist right away which is a tradeoff but it was the only way I could seem to get pickling to work correctly.

Are there changes in behavior for the user?

Related issue number

fixes #683

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modifications, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep the list in alphabetical order, the file is sorted by name.
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<category> for example (588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure category is one of the following:
      • .bugfix: Signifying a bug fix.
      • .feature: Signifying a new feature.
      • .breaking: Signifying a breaking change or removal of something public.
      • .doc: Signifying a documentation improvement.
      • .packaging: Signifying a packaging or tooling change that may be relevant to downstreams.
      • .contrib: Signifying an improvement to the contributor/development experience.
      • .misc: Anything that does not fit the above; usually, something not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

Comment thread frozenlist/__init__.py Fixed
@codecov

codecov Bot commented May 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7f26355) to head (9e27974).

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #717   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines          419       438   +19     
  Branches        10        11    +1     
=========================================
+ Hits           419       438   +19     
Flag Coverage Δ
CI-GHA 100.00% <100.00%> (ø)
OS-Linux 100.00% <100.00%> (ø)
OS-Windows 97.03% <100.00%> (+0.13%) ⬆️
OS-macOS 100.00% <100.00%> (ø)
Py-3.10.11 100.00% <100.00%> (ø)
Py-3.10.22 100.00% <100.00%> (ø)
Py-3.11.17 100.00% <100.00%> (ø)
Py-3.11.9 100.00% <100.00%> (ø)
Py-3.12.10 100.00% <100.00%> (ø)
Py-3.12.15 ?
Py-3.12.16 100.00% <100.00%> (?)
Py-3.13.17 100.00% <100.00%> (ø)
Py-3.13.18 100.00% <100.00%> (?)
Py-3.14.10 100.00% <100.00%> (ø)
Py-3.14.10t 100.00% <100.00%> (ø)
Py-3.14.9 100.00% <100.00%> (ø)
Py-pypy3.10.16-7.3.19 ?
VM-macos-latest 100.00% <100.00%> (ø)
VM-ubuntu-latest 100.00% <100.00%> (ø)
VM-windows-11-arm 97.03% <100.00%> (+0.13%) ⬆️
VM-windows-latest 97.03% <100.00%> (+0.13%) ⬆️
pytest 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bdraco

bdraco commented May 18, 2026

Copy link
Copy Markdown
Member

@Vizonex would you bring this back up to date?

@Vizonex

Vizonex commented May 19, 2026

Copy link
Copy Markdown
Member Author

@bdraco Sorry for the wait. I can.

@greptile-apps

This comment has been minimized.

@greptile-apps

greptile-apps Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 2/5 Tier: apex

[Medium impact] The PR changes pickle round trips for the public FrozenList type.

The PR is not ready to merge because imports with extensions disabled, circular lists, and subclass restoration still break.

Reviews (5) · Last reviewed commit: "Merge branch 'master' into fix-pickeling" · Reviewed by Greptile

Comment thread frozenlist/__init__.py
from ._frozenlist import FrozenList as CFrozenList # type: ignore
except ImportError: # pragma: no cover
pass
FrozenList = PyFrozenList

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Disabling extensions breaks imports

With FROZENLIST_NO_EXTENSIONS=1, this assignment is skipped, and the renamed class no longer defines FrozenList. A fresh from frozenlist import FrozenList raises ImportError, including in the configured pure-Python test runs. Set FrozenList = PyFrozenList before the conditional, then replace it when the extension loads.

Comment thread frozenlist/__init__.py
Comment on lines +83 to +88
def __reduce_ex__(self, protocol):
return type(self).__unreduce_ex__, (self._frozen, self._items)

PyFrozenList = FrozenList
@classmethod
def __unreduce_ex__(cls, frozen: bool, _items: list):
fl = cls(_items)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Cyclic lists lose contents

Passing _items as constructor arguments loses contents when a list contains itself. For x = PyFrozenList([1, 2]); x.append(x), the default pickle round trip returns an empty list, and deepcopy replaces the self-reference with a different list. This also violates the requirement in AGENTS.md that both implementations behave alike, since Cython's __deepcopy__ still works. Create the object before restoring its items, and fix both reducers.

Context Used: AGENTS.md (source)

Comment thread frozenlist/_frozenlist.pyx Outdated
Comment on lines +158 to +162
return type(self).__unreduce_ex__, (self.frozen, self._items)

@classmethod
def __unreduce_ex__(cls, frozen: bool, _items: list):
fl = cls(_items)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Subclasses lose saved state

Calling cls(_items) assumes every subclass accepts items in its constructor, while the reducer also drops extra subclass state. aiosignal.Signal takes an owner instead. Unpickling calls Signal(callbacks), drops its callbacks, and replaces _owner with that list. Preserve subclass state and restore it without passing items to the subclass constructor.

Comment thread frozenlist/__init__.py Resolved
Comment thread tests/test_frozenlist.py Resolved
Comment thread tests/test_frozenlist.py Resolved
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Comment thread frozenlist/__init__.py Resolved
Vizonex and others added 6 commits October 17, 2026 17:25
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Comment thread CHANGES/717.bugfix.rst Resolved
Vizonex and others added 2 commits October 17, 2026 17:40
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Comment thread CHANGES/717.bugfix.rst
@@ -0,0 +1,2 @@
Fixed pickling in Cython Extension.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 News fragment uses wrong number

This PR closes #683, but the fragment is named CHANGES/717.bugfix.rst. AGENTS.md requires fragments to use the linked issue number. Rename it to CHANGES/683.bugfix.rst before merging.

Context Used: AGENTS.md (source)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Release new version (with fixes for pickling)?

3 participants