This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: "import decimal" fails in Turkish locale
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: belopolsky Nosy List: belopolsky, dmalcolm, mark.dickinson, python-dev, rhettinger, skrah
Priority: normal Keywords: patch

Created on 2011-04-11 22:46 by dmalcolm, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
decimal.py.patch dmalcolm, 2011-04-11 22:46
Messages (6)
msg133550 - (view) Author: Dave Malcolm (dmalcolm) (Python committer) Date: 2011-04-11 22:46
For Python 2 (here with 2.7.1):
$ python -c 'import locale; locale.setlocale(locale.LC_ALL, "tr_TR.UTF-8"); import decimal'

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/python2.7/decimal.py", line 3715, in <module>
    val = globals()[globalname]
KeyError: 'ROUND_CEiLiNG'

The issue is that 'round_ceiling'.upper() is 'ROUND_CEiLiNG' in the Turkish locale, rather than 'ROUND_CEILING', as one might expect.

A workaround for this may be to convert the str instances to unicode
first, then call upper on them, then convert back to str.

This would work since upper() for a unicode instance is locale-independent as
per issue 1528802.
(though there seems to have been some debate there).

Patch attached, though it doesn't yet contain a test case.

Only affects Python 2; with Python 3, the symbols are already stored as unicode internally.

Reported downstream as:
  https://bugzilla.redhat.com/show_bug.cgi?id=694928
which has links to various other reports on this
msg133556 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-04-12 00:28
New changeset b4b1f557d563 by Raymond Hettinger in branch '2.7':
Issue #11830: Remove unnecessary introspection code in the decimal module.
http://hg.python.org/cpython/rev/b4b1f557d563
msg133582 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2011-04-12 14:01
Shouldn't this be forward ported to 3.3?  Even though there is no bug in 3.x, code using an explicit dict is cleaner and more robust than the current code that relies on introspection to find methods that start with '_round_'.
msg133588 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-04-12 16:06
New changeset f4adc2926bf5 by Raymond Hettinger in branch '2.7':
Neaten-up the fix to issue 11830
http://hg.python.org/cpython/rev/f4adc2926bf5
msg133589 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-04-12 16:08
+0 on forward porting
msg133640 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-04-13 03:09
New changeset f5d5f3f4c081 by Alexander Belopolsky in branch '3.2':
Issue #11830: Remove unnecessary introspection code in the decimal module.
http://hg.python.org/cpython/rev/f5d5f3f4c081
History
Date User Action Args
2022-04-11 14:57:16adminsetgithub: 56039
2011-04-13 03:10:42belopolskysetstage: resolved
type: behavior
versions: + Python 3.2, Python 3.3
2011-04-13 03:09:03python-devsetmessages: + msg133640
2011-04-12 16:13:40r.david.murraysetnosy: + mark.dickinson, skrah
2011-04-12 16:08:28rhettingersetassignee: rhettinger -> belopolsky
messages: + msg133589
2011-04-12 16:06:10python-devsetmessages: + msg133588
2011-04-12 14:01:43belopolskysetnosy: + belopolsky
messages: + msg133582
2011-04-12 00:28:59rhettingersetstatus: open -> closed
resolution: fixed
2011-04-12 00:28:03python-devsetnosy: + python-dev
messages: + msg133556
2011-04-11 23:06:20rhettingersetassignee: rhettinger

nosy: + rhettinger
2011-04-11 22:46:56dmalcolmcreate