Conversation
`isinstance(x, int | float)` evaluates the PEP 604 union at runtime, which raises TypeError on Python 3.9 (still supported by Odoo 16) when generating the EN16931 XML. Use the equivalent tuple form. Fixes akretion#74 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Hi @alexis-via, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #74.
On the 16.0 branch,
account_invoice_en16931/models/account_move_line.pycallsin two places. The
int | floatunion is evaluated at runtime, which only works on Python >= 3.10; Odoo 16 still supports Python 3.9 (e.g. Debian 11), where EN16931 XML generation fails on every invoice line withThis switches both call sites to the equivalent tuple form
(int, float). The repo's ruff config targetspy310, soUP038would flag the tuple form; I added# noqa: UP038so pre-commit stays green (ruff 0.6.8checkandformat --checkpass on the file).Checked with CPython 3.9.25:
isinstance(1.0, int | float)raises the TypeError above, whileisinstance(1.0, (int, float))/isinstance(None, (int, float))/isinstance(5, (int, float))returnTrue/False/True, the same results as the union form on 3.10+.17.0/18.0 use the same expression, but they require Python >= 3.10, so no change is needed there.
🤖 Generated with Claude Code