set_locale contextmanager
See original GitHub issueThe locale
module documentation mentions that setting and restoring the locale is generally a “bad idea”:
It is generally a bad idea to call setlocale() in some library routine, since as a side effect it affects the entire program. Saving and restoring it is almost as bad: it is expensive and affects other threads that happen to run before the settings have been restored.
My question is: Should we really provide it in our public API if the Python docs discourage it?
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
python - Temporarily override locale with a context manager
That being said, it is possible to build a custom context manager: ... from locale import getlocale, setlocale from contextlib import ...
Read more >Use a temporary_locale context manager · Issue #1347 · getpelican ...
Can set a temporary locale if provided ''' orig_locale = locale.setlocale(locale.LC_ALL) if temp_locale is not None: locale.setlocale(locale.
Read more >contextmanager for locale
I propose to add this (or a similar) contextmanager: @contextmanager def localectx(category, newlocale=None): ... locale.setlocale(category, newlocale)
Read more >contextlib — Utilities for with-statement contexts ... - Python Docs
This module provides utilities for common tasks involving the with statement. For more information see also Context Manager Types and With Statement Context ......
Read more >Examples
A context manager can remove roles that have already been assigned within the context to an account. This is performed using the unassignRights...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @pllim 👍
Removing it from the public API seems fine to me with deprecation (assuming someone else wants to do the PR 😄). Removing it completely seems to me like more work than it’s worth unless we have a real-world bug that shows up. Though I am not sure anyone has seriously looked at doing that removal so level of effort is unclear.