Skip to content

Restore LC_NUMERIC when a localized format raises - #2474

Merged
andrewgsavage merged 2 commits into
hgrecco:masterfrom
barlowa124:override-locale-restore-2469
Oct 11, 2026
Merged

andrewgsavage merged 2 commits into
hgrecco:masterfrom
barlowa124:override-locale-restore-2469

Conversation

@barlowa124

Copy link
Copy Markdown
Contributor

override_locale restored LC_NUMERIC on the line after its yield, so an exception in the wrapped formatting call skipped the restore and left the process-wide locale changed. The restore is now in a finally block, so both the raising and successful paths clean up.

The saved setting also switched from getlocale() to a bare setlocale(LC_NUMERIC) call, which returns the current locale name in the form setlocale accepts back. getlocale() returns a (language, encoding) pair that setlocale rejects on Windows, so even the successful path could fail to restore.

A new test in test_babel.py asserts the locale survives both a ValueError inside the formatter call and a successful localized format. It needs a de_DE locale and skips where one is unavailable.

barlowa124 and others added 2 commits October 10, 2026 22:01
override_locale restored LC_NUMERIC only after the yield, so an
exception in the wrapped formatting call skipped the restore and
left the process-wide locale changed. Save the previous setting
with setlocale(LC_NUMERIC) rather than getlocale(): the returned
name round-trips on platforms where the (language, encoding) pair
is rejected, and restore it in a finally block so both the raising
and successful paths clean up.
@andrewgsavage
andrewgsavage merged commit d534f5f into hgrecco:master Oct 11, 2026
50 checks passed
@codspeed

codspeed Bot commented Oct 11, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 448 untouched benchmarks
⏩ 448 skipped benchmarks1


Comparing barlowa124:override-locale-restore-2469 (7fdccc3) with master (c629cc3)

Open in CodSpeed

Footnotes

  1. 448 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

barlowa124 added a commit to barlowa124/barlowa124 that referenced this pull request Oct 20, 2026
…un oncology ledger

- Record newly merged upstream PRs: rdkit#9670, rdkit#9674, openmm#5487,
  deeptools/pyBigWig#167, sgkit-dev/sgkit#1353, hgrecco/pint#2474,
  and openmc-dev/openmc#4188
- Add ailm-inspectable to the Trustworthy ML and scientific agents table
- Update oncology-coscientist summary with the 68-run ledger and 2x3
  Qwen2.5-3B/14B sweep
- Add .gitignore for local untracked notes

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.

Localized formatting leaves LC_NUMERIC changed after an exception

2 participants