Skip to content

fix: HexInt.to_yaml crashes with TypeError when given an int#220

Open
gaoflow wants to merge 1 commit into
crdoconnor:masterfrom
gaoflow:fix-hexint-to-yaml-crash-on-int
Open

fix: HexInt.to_yaml crashes with TypeError when given an int#220
gaoflow wants to merge 1 commit into
crdoconnor:masterfrom
gaoflow:fix-hexint-to-yaml-crash-on-int

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 28, 2026

Copy link
Copy Markdown

HexInt.to_yaml() calls utils.is_hexadecimal(data) which performs a regex match on the input. When data is a Python int, re.match() raises TypeError since it requires a string.

Reorder the isinstance(data, int) check before the is_hexadecimal call so int values are correctly serialized to hex strings like "0xff", and non-string non-int values produce a clean YAMLSerializationError instead of a TypeError crash.

Fixes round-trip: as_document({'x': 26}, Map({'x': HexInt()})) now works instead of crashing.

AI disclosure: This PR was created using an AI assistant (Claude Code) under my direction. I reviewed the code, confirmed the bug, and validated the fix meets the project's standards.

HexInt.to_yaml() calls utils.is_hexadecimal(data) which performs a
regex match on the input. When data is a Python int, re.match()
raises TypeError since it requires a string.

Reorder the isinstance(data, int) check before the is_hexadecimal
call so int values are correctly serialized to hex strings like
"0xff", and non-string non-int values produce a clean
YAMLSerializationError instead of a TypeError crash.

Fixes round-trip: as_document({'x': 26}, Map({'x': HexInt()}))
now works instead of crashing.
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