Skip to content

Commit

Permalink
update collection package
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Dec 14, 2021
1 parent 6f86eff commit f0ec0b3
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions emborg/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@
__version__ = "0.5.0"
__released__ = "2021-01-27"

class NothingGiven:
def __bool__(self):
return False


# Utilities {{{1
# split_lines() {{{2
def split_lines(text, comment=None, strip=False, cull=False, sep=None):
"""Split lines
Expand All @@ -59,6 +57,13 @@ def split_lines(text, comment=None, strip=False, cull=False, sep=None):
return lines


# Null {{{2
# class that is used as a default in functions to signal nothing was given
class Null:
def __bool__(self):
return False


# Collection {{{1
class Collection(object):
fmt = '{v}' # default value format
Expand Down Expand Up @@ -115,11 +120,11 @@ def items(self):
except AttributeError:
return list(enumerate(self.collection))

def get(self, key, default=NothingGiven):
def get(self, key, default=Null):
try:
return self.collection[key]
except (KeyError, IndexError):
if default == NothingGiven:
if default == Null:
raise
return default

Expand Down

0 comments on commit f0ec0b3

Please sign in to comment.