Skip to content

Perform boolean serialization before integer serialization.#368

Open
dthiele wants to merge 1 commit intorobshakir:masterfrom
dthiele:fix-serialization-order-0
Open

Perform boolean serialization before integer serialization.#368
dthiele wants to merge 1 commit intorobshakir:masterfrom
dthiele:fix-serialization-order-0

Conversation

@dthiele
Copy link
Copy Markdown
Contributor

@dthiele dthiele commented Mar 25, 2026

Hi,

as a bool is an instance of int in Python (cf. https://peps.python.org/pep-0285/#specification), this PR changes the native type serialization order of YangDataSerialiser.default() so that bool is serialized before int. Otherwise, bools will be serialized as 0 or 1.

Best regards,
Daniel

@dthiele
Copy link
Copy Markdown
Contributor Author

dthiele commented Mar 25, 2026

The failed "black checks" from tox -e black also fail on a plain master clone.

@JoseIgnacioTamayo
Copy link
Copy Markdown
Collaborator

The failed "black checks" from tox -e black also fail on a plain master clone.

#369 would fix those

@JoseIgnacioTamayo
Copy link
Copy Markdown
Collaborator

As there is no change in the unittests, I wonder if this PR has actually any effects, or changes anything.

@dthiele , could you please add a test under tests/serialize that shows the effect of this change?

@dthiele
Copy link
Copy Markdown
Contributor Author

dthiele commented Apr 3, 2026

I stumbled across this issue, when I accidentally passed a plain dict (as returned by Python's json.load()) into pybindJSON.dumps(). I'm not sure if this is one of the intended use cases? If it is, I will, of course, write a corresponding test case.

@JoseIgnacioTamayo
Copy link
Copy Markdown
Collaborator

I stumbled across this issue, when I accidentally passed a plain dict (as returned by Python's json.load()) into pybindJSON.dumps(). I'm not sure if this is one of the intended use cases? If it is, I will, of course, write a corresponding test case.

Looking at the unit test code in https://github.com/robshakir/pyangbind/tree/master/tests/serialise and in my experience using pyangbind I would say no, the sequence or steps you performed is not the intended use.

I would suggest you raise an Issue linked to this PR. If other people upvote or comment there, it means it is a common use and this fix is needed.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants