Fokko commented on code in PR #4357:
URL: https://github.com/apache/iceberg-python/pull/4357#discussion_r4561123743


##########
pyiceberg/utils/transient.py:
##########
@@ -0,0 +1,45 @@
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+"""Support for pickling objects that hold process-local state such as locks 
and caches."""
+
+from typing import Any, ClassVar
+
+
+class _TransientStateMixin:
+    """Excludes process-local attributes from pickling and rebuilds them on 
unpickle.
+
+    Subclasses list those attributes in `_transient_attrs`, create them in 
`_init_transient`,
+    and call `_init_transient` from `__init__`. Place the mixin before other 
bases so its
+    `__getstate__` and `__setstate__` take precedence.
+    """
+
+    _transient_attrs: ClassVar[tuple[str, ...]] = ()
+
+    def _init_transient(self) -> None:
+        """Create the attributes listed in `_transient_attrs`."""
+
+    def __getstate__(self) -> dict[str, Any]:

Review Comment:
   Nit: `__getstate__`/`__setstate__` here only round-trip `self.__dict__`, so 
a subclass that uses `__slots__` (and doesn't mirror its slots into `__dict__`) 
would silently lose its slotted state on pickle. The hand-written versions on 
main had the same behavior, so this is not a regression, but since this is now 
the central mechanism future adopters might hit it. Maybe worth a line in the 
docstring that slotted subclasses need their own handling.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to