sandyharvie opened a new issue, #3466:
URL: https://github.com/apache/fory/issues/3466
### Feature Request
I would like to use `pyfory` as a drop-in replacement for `cloudpickle`, but
attempting to serialize a dataclass with a `tuple` field currently results in a
`TypeError`.
```
>>> import pyfory
>>> fory = pyfory.Fory(xlang=False, ref=True, strict=False)
>>> import dataclasses
>>> @dataclasses.dataclass(frozen=True)
... class Foo:
... bar: tuple[str, int]
...
>>> foo = Foo(bar=("a", 1))
>>> fory.serialize(foo)
Traceback (most recent call last):
File "<python-input-28>", line 1, in <module>
fory.serialize(foo)
~~~~~~~~~~~~~~^^^^^
File "python/pyfory/serialization.pyx", line 1292, in
pyfory.serialization.Fory.serialize
File "python/pyfory/serialization.pyx", line 1330, in
pyfory.serialization.Fory._serialize
File "python/pyfory/serialization.pyx", line 1363, in
pyfory.serialization.Fory.write_ref
File "python/pyfory/serialization.pyx", line 1828, in
pyfory.serialization.Serializer.write
File
"/home/charvie/.venv/py313/lib/python3.13/site-packages/pyfory/struct.py", line
1127, in write
self._replace().write(buffer, value)
~~~~~~~~~~~~~^^
File
"/home/charvie/.venv/py313/lib/python3.13/site-packages/pyfory/struct.py", line
1140, in _replace
typeinfo.serializer = DataClassSerializer(self.fory, self.type_,
self.xlang)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/home/charvie/.venv/py313/lib/python3.13/site-packages/pyfory/struct.py", line
343, in __init__
self._field_infos, self._field_metas = _extract_field_infos(fory, clz,
self._type_hints, xlang=xlang)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/home/charvie/.venv/py313/lib/python3.13/site-packages/pyfory/struct.py", line
248, in _extract_field_infos
serializer = infer_field(field_name, unwrapped_type, visitor,
types_path=[])
File
"/home/charvie/.venv/py313/lib/python3.13/site-packages/pyfory/type_util.py",
line 250, in infer_field
raise TypeError(f"Collection types should be {list, dict} instead of
{type_}")
TypeError: Collection types should be (<class 'list'>, <class 'dict'>)
instead of tuple[str, int]
```
### Is your feature request related to a problem? Please describe
_No response_
### Describe the solution you'd like
_No response_
### Describe alternatives you've considered
_No response_
### Additional context
_No response_
--
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]