Skip to content

Commit

Permalink
Result object now resolves as False when unsuccessful and no longer e…
Browse files Browse the repository at this point in the history
…rrors on requests for pods or info. Fixes #13.
  • Loading branch information
jaraco committed Feb 14, 2021
1 parent b8418f1 commit 13c921a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ v4.3.0

* Added ``Client.from_env()`` to initialize a client loading the
API key from the keyring or environment.
* #13: ``Result`` objects now resolve as False and return empty
``info`` and ``pods`` attributes when query was unsuccessful.

v4.2.0
======
Expand Down
9 changes: 4 additions & 5 deletions wolframalpha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,6 @@ class Result(ErrorHandler, Document):
Handles processing the response for the programmer.
"""

_attr_types = dict(
pod=Pod.from_doc,
)

def __init__(self, stream):
doc = xmltodict.parse(stream, dict_constructor=dict)['queryresult']
super(Result, self).__init__(doc)
Expand All @@ -252,7 +248,7 @@ def info(self):

@property
def pods(self):
return self.pod
return Pod.from_doc(self.get('pod'))

@property
def assumptions(self):
Expand All @@ -268,6 +264,9 @@ def __iter__(self):
def __len__(self):
return sum(1 for _ in self.info)

def __bool__(self):
return bool(len(self))

@property
def results(self):
"""
Expand Down

0 comments on commit 13c921a

Please sign in to comment.