Skip to content

Commit b5cf301

Browse files
committed
python#3929: dbm.open() would try to raise a tuple. This does not work anymore with python 3.0.
Reviewed by Georg Brandl.
1 parent 7de5f29 commit b5cf301

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

Lib/dbm/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ def open(file, flag = 'r', mode = 0o666):
7676
# file doesn't exist and the new flag was used so use default type
7777
mod = _defaultmod
7878
else:
79-
raise error("need 'c' or 'n' flag to open new db")
79+
raise error[0]("need 'c' or 'n' flag to open new db")
8080
elif result == "":
8181
# db type cannot be determined
82-
raise error("db type could not be determined")
82+
raise error[0]("db type could not be determined")
8383
elif result not in _modules:
84-
raise error("db type is {0}, but the module is not "
85-
"available".format(result))
84+
raise error[0]("db type is {0}, but the module is not "
85+
"available".format(result))
8686
else:
8787
mod = _modules[result]
8888
return mod.open(file, flag, mode)

Lib/test/test_dbm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ def keys_helper(self, f):
5757
def test_error(self):
5858
self.assert_(issubclass(self.module.error, IOError))
5959

60+
def test_anydbm_not_existing(self):
61+
self.assertRaises(dbm.error, dbm.open, _fname)
62+
6063
def test_anydbm_creation(self):
6164
f = dbm.open(_fname, 'c')
6265
self.assertEqual(list(f.keys()), [])

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Core and Builtins
2020
Library
2121
-------
2222

23+
- Issue #3929: When the database cannot be opened, dbm.open() would incorrectly
24+
raise a TypeError: "'tuple' object is not callable" instead of the expected
25+
dbm.error.
26+
2327
- Bug #3884: Make the turtle module toplevel again.
2428

2529
- Issue #3547: Fixed ctypes structures bitfields of varying integer

0 commit comments

Comments
 (0)