Repository: pytest-dev/execnet

Issue:
FYI type for Python2 strings unserialization changed with 2.1.0
I don't think many people will care, as this only happens with some very specific settings, but I thought I report it anyway. I noticed because in devpi-server I wrote my own un-/serializer implementation for performance reasons and the tests still compared to the execnet implementation. Afaik Python2 strings were never used in devpi-server databases and the new implementation is in use since 6.2.0 released August 2021.

With pre 2.1.0:
>>> from execnet.gateway_base import Unserializer
>>> from devpi_server.fileutil import BytesIO
>>> Unserializer(BytesIO(b'M\x00\x00\x00\x01aQ'), strconfig=(False, False)).load(versioned=False)
b'a'

With 2.1.0:
>>> from execnet.gateway_base import Unserializer
>>> from devpi_server.fileutil import BytesIO
>>> Unserializer(BytesIO(b'M\x00\x00\x00\x01aQ'), strconfig=(False, False)).load(versioned=False)
'a'

Discussion:

Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index a05344b..8fee91e 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,3 +1,9 @@
+TBD
+---
+
+* `#267 <https://github.com/pytest-dev/execnet/issue/267>`__ Fixed regression
+  in 2.1.0 where the ``strconfig`` argument to ``load``/``loads`` is ignored.
+
 2.1.0 (2024-04-05)
 ------------------
 
diff --git a/src/execnet/gateway_base.py b/src/execnet/gateway_base.py
index f533306..9ba25b4 100644
--- a/src/execnet/gateway_base.py
+++ b/src/execnet/gateway_base.py
@@ -1391,9 +1391,7 @@ class Unserializer:
             gw: BaseGateway | None = channel_or_gateway.gateway
         else:
             gw = channel_or_gateway
-        if channel_or_gateway is None:
-            strconfig = None
-        else:
+        if channel_or_gateway is not None:
             strconfig = channel_or_gateway._strconfig
         if strconfig:
             self.py2str_as_py3str, self.py3str_as_py2str = strconfig


Test patch:
diff --git a/testing/test_serializer.py b/testing/test_serializer.py
index 6453939..aff41a9 100644
--- a/testing/test_serializer.py
+++ b/testing/test_serializer.py
@@ -163,3 +163,8 @@ def test_tuple_nested_with_empty_in_between(dump, load) -> None:
     tp, s = load(p)
     assert tp == "tuple"
     assert s == "(1, (), 3)"
+
+
+def test_py2_string_loads() -> None:
+    """Regression test for #267."""
+    assert execnet.loads(b"\x02M\x00\x00\x00\x01aQ") == b"a"