Skip to content

[16.0][FIX] account_invoice_en16931: isinstance() tuple for Python 3.9 - #84

Open
Anai-Guo wants to merge 1 commit into
akretion:16.0from
Anai-Guo:fix/16-isinstance-py39-union
Open

Anai-Guo wants to merge 1 commit into
akretion:16.0from
Anai-Guo:fix/16-isinstance-py39-union

Conversation

@Anai-Guo

Copy link
Copy Markdown

Fixes #74.

On the 16.0 branch, account_invoice_en16931/models/account_move_line.py calls

isinstance(vat_dict.get("vat_rate"), int | float)

in two places. The int | float union 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 with

TypeError: unsupported operand type(s) for |: 'type' and 'type'

This switches both call sites to the equivalent tuple form (int, float). The repo's ruff config targets py310, so UP038 would flag the tuple form; I added # noqa: UP038 so pre-commit stays green (ruff 0.6.8 check and format --check pass on the file).

Checked with CPython 3.9.25: isinstance(1.0, int | float) raises the TypeError above, while isinstance(1.0, (int, float)) / isinstance(None, (int, float)) / isinstance(5, (int, float)) return True / 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

`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>
@ak-git-bot

Copy link
Copy Markdown

Hi @alexis-via,
some modules you are maintaining are being modified, check this out!

@ak-git-bot ak-git-bot added mod:account_invoice_en16931 Module account_invoice_en16931 series:16.0 labels Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:account_invoice_en16931 Module account_invoice_en16931 series:16.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants