Skip to content

Commit

Permalink
fix: Raise exception if card name is invalid. Fixes #467
Browse files Browse the repository at this point in the history
  • Loading branch information
lo5 committed Jan 4, 2021
1 parent 511c7a1 commit c7f5ff7
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions py/h2o_wave/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,16 @@ def _guard_primitive_dict_values(d: Dict[str, Any]):
_guard_primitive(x)


def _guard_str_key(key: str):
if not _is_str(key):
raise KeyError('key must be str')
if ' ' in key:
raise KeyError('keys cannot contain spaces')


def _guard_key(key: str):
if _is_str(key):
if ' ' in key:
raise KeyError('keys cannot contain spaces')
_guard_str_key(key)
else:
if not _is_int(key):
raise KeyError('invalid key type: want str or int')
Expand Down Expand Up @@ -455,11 +461,7 @@ def add(self, key: str, card: Any) -> Ref:
Returns:
A reference to the added card.
"""
if key is None:
raise ValueError('card must have a key')

if not _is_str(key):
raise ValueError('key must be str')
_guard_str_key(key)

props: Optional[dict] = None

Expand Down Expand Up @@ -508,11 +510,11 @@ def __setitem__(self, key, card):
self.add(key, card)

def __getitem__(self, key: str) -> Ref:
if not _is_str(key):
raise ValueError('key must be str')
_guard_str_key(key)
return Ref(self, key)

def __delitem__(self, key: str):
_guard_str_key(key)
self._track(dict(k=key))


Expand Down

0 comments on commit c7f5ff7

Please sign in to comment.