Skip to content

[python] NamedTuple support #4056

Description

@tchan09

Search before asking

  • I had searched in the issues and found no similar issues.

Version

pyfory 1.7.3
python 3.13

Component(s)

Python

Minimal reproduce step

With pyfory 1.7.3, it doesn't look like NamedTuple objects are supported.

Test case:

import pytest
import pyfory

class Record(NamedTuple):
    name: str
    values: tuple
    count: int

@pytest.fixture(scope="session")
def fory() -> pyfory.Fory:
    fory = pyfory.Fory(xlang=False, ref=False, strict=False, compatible=False)
    return fory

@pytest.fixture(scope="session")
def record() -> Record:
    return Record("sample", (1.0, 2.0, 3.0), 42)

def test_namedtuple_fory(fory: pyfory.Fory, record: Record):
    data = fory.dumps(record)
    restored = fory.loads(data)

    assert isinstance(restored, Record)
    assert restored == record

What did you expect to see?

I expect NamedTuple be able to roundtrip when using python to python marshalling without cross-language support.

What did you see instead?

I get this error:

FAILED test_serialization.py::test_namedtuple_fory - TypeError: Record.__new__() missing 3 required positional arguments: 'name', 'values', and 'count'

Anything Else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions