Skip to content

Commit 42e2dcf

Browse files
author
Johannes Gijsbers
committed
Add docstring to safeget method.
Remove handling of invalid propname (YAGNI).
1 parent 988a943 commit 42e2dcf

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

roundup/hyperdb.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: hyperdb.py,v 1.94 2003-11-16 20:01:16 jlgijsbers Exp $
18+
# $Id: hyperdb.py,v 1.95 2003-11-16 22:56:46 jlgijsbers Exp $
1919

2020
"""
2121
Hyperdatabase implementation, especially field types.
@@ -573,9 +573,13 @@ def index(self, nodeid):
573573
raise NotImplementedError
574574

575575
def safeget(self, nodeid, propname, default=None):
576+
"""Safely get the value of a property on an existing node of this class.
577+
578+
Return 'default' if the node doesn't exist.
579+
"""
576580
try:
577581
return self.get(nodeid, propname)
578-
except (KeyError, IndexError):
582+
except IndexError:
579583
return default
580584

581585
class HyperdbValueError(ValueError):

test/db_test_base.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: db_test_base.py,v 1.9 2003-11-16 19:59:06 jlgijsbers Exp $
18+
# $Id: db_test_base.py,v 1.10 2003-11-16 22:56:46 jlgijsbers Exp $
1919

2020
import unittest, os, shutil, errno, imp, sys, time, pprint
2121

@@ -801,12 +801,8 @@ def testImportExport(self):
801801
def testSafeGet(self):
802802
# existent nodeid, existent property
803803
self.assertEqual(self.db.user.safeget('1', 'username'), 'admin')
804-
# existent nodeid, nonexistent property
805-
self.assertEqual(self.db.user.safeget('1', 'nonexistent'), None)
806804
# nonexistent nodeid, existent property
807805
self.assertEqual(self.db.user.safeget('999', 'username'), None)
808-
# nonexistent nodeid, nonexistent property
809-
self.assertEqual(self.db.user.safeget('999', 'nonexistent'), None)
810806
# different default
811807
self.assertEqual(self.db.issue.safeget('999', 'nosy', []), [])
812808

0 commit comments

Comments
 (0)