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: Incorrect exception raising in dbm.open on non-existing DB
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.0
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, georg.brandl, hagen
Priority: normal Keywords: needs review, patch

Created on 2008-09-22 10:07 by hagen, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
dbm.patch hagen, 2008-09-22 10:07
dbm-2.patch amaury.forgeotdarc, 2008-09-22 11:13
Messages (5)
msg73563 - (view) Author: Hagen Fürstenau (hagen) Date: 2008-09-22 10:07
Opening a dbm database which doesn't exist without a "c" or "n" flag
results in this exception:

>>> import dbm
>>> dbm.open("abc")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/MP.shadow/hagenf/local/src/py3k/Lib/dbm/__init__.py", line
79, in open
    raise error("need 'c' or 'n' flag to open new db")
TypeError: 'tuple' object is not callable

"error" is a tuple of dbm's own exception class and IOError, but this
doesn't seem to make sense in the present code and Python 3.0. The
attached patch fixes the problem and adds a test for the correct
exception being raised.
msg73564 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-09-22 11:13
dbm.error is documented as a tuple, and I'd prefer not to change this:
  http://docs.python.org/dev/3.0/library/dbm.html#dbm.error
Since it says that its first member is another dbm.error exception,
we could simply raise error[0](message)

Attached another patch, with the same test case.
msg73570 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-09-22 12:32
Amaury's patch looks good.
msg73819 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-09-25 22:29
Did you know that...
with python 2.x, "raise (x,y,z)" is equivalent to "raise x"!
I could not find this in the documentation.

Committed the patch to py3k as r66622.
msg73838 - (view) Author: Hagen Fürstenau (hagen) Date: 2008-09-26 08:31
I didn't know until I had googled this:

http://mail.python.org/pipermail/python-3000/2007-March/005916.html
History
Date User Action Args
2022-04-11 14:56:39adminsetgithub: 48179
2008-09-26 08:31:18hagensetmessages: + msg73838
2008-09-25 22:29:21amaury.forgeotdarcsetstatus: open -> closed
resolution: fixed
messages: + msg73819
2008-09-22 12:32:03georg.brandlsetnosy: + georg.brandl
messages: + msg73570
2008-09-22 11:13:24amaury.forgeotdarcsetkeywords: + needs review
files: + dbm-2.patch
messages: + msg73564
nosy: + amaury.forgeotdarc
2008-09-22 10:07:58hagencreate