Skip to content

fix(python): emit widening integer casts - #5087

Merged
dbrattli merged 2 commits into
mainfrom
fix/python-int-widening-cast
Oct 15, 2026
Merged

dbrattli merged 2 commits into
mainfrom
fix/python-int-widening-cast

Conversation

@MangelMaxime

@MangelMaxime MangelMaxime commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

The Thoth.Json.Python 0.7.0 update exposes Pyright errors in codec.py: F# converts byte and uint16 values to uint32, but Python code generation drops those widening casts and retains the source wrapper. Subsequent operations can consequently use the wrong integer width.

Emit the target wrapper constructor when translating numeric casts, alongside the existing int32 and floating-point handling. Cover sbyte-to-int16, byte-to-uint16, byte-to-uint32, and uint16-to-uint32 conversions with runtime-type assertions and shift results compared as plain integers. This avoids wrapper equality masking an incorrect result by truncating the expected value.

Incorporates the regression coverage from #5086. The generated codec remains covered by Pyright without adding an exclusion.

@github-actions

Copy link
Copy Markdown
Contributor

Python Type Checking Results (Pyright)

Metric Value
Total errors 34
Files with errors 4
Excluded files 4
New errors ✅ No
Excluded files with errors (4 files)

These files have known type errors and are excluded from CI. Remove from pyrightconfig.ci.json as errors are fixed.

File Errors Status
temp/tests/Python/test_hash_set.py 18 Excluded
temp/tests/Python/test_applicative.py 12 Excluded
temp/tests/Python/test_nested_and_recursive_pattern.py 2 Excluded
temp/tests/Python/fable_modules/thoth_json_python/encode.py 2 Excluded

@dbrattli
dbrattli merged commit 07989b1 into main Oct 15, 2026
44 checks passed
@dbrattli
dbrattli deleted the fix/python-int-widening-cast branch October 15, 2026 21:21
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