question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

set_locale contextmanager

See original GitHub issue

The 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:closed
  • Created 4 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
MSeifert04commented, Oct 30, 2019

Thanks @pllim 👍

1reaction
taldcroftcommented, Sep 2, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found