Skip to content

Commit

Permalink
Merge pull request #14 from llazzaro/master
Browse files Browse the repository at this point in the history
fix #13 check if identifier is None and raise an exception to let the user know that the identifier is invalid
  • Loading branch information
mcs07 committed Jun 5, 2016
2 parents 9de4f2c + f2cfc9a commit 9c49b42
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pubchempy.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ def request(identifier, namespace='cid', domain='compound', operation=None, outp
Full specification at http://pubchem.ncbi.nlm.nih.gov/pug_rest/PUG_REST.html
"""
if not identifier:
raise ValueError('identifier/cid cannot be None')
# If identifier is a list, join with commas into string
if isinstance(identifier, int):
identifier = str(identifier)
Expand Down Expand Up @@ -461,6 +463,7 @@ def memoized_property(fget):
request.
"""
attr_name = '_{0}'.format(fget.__name__)

@functools.wraps(fget)
def fget_memoized(self):
if not hasattr(self, attr_name):
Expand Down Expand Up @@ -777,7 +780,7 @@ def synonyms(self):
if self.cid:
results = get_json(self.cid, operation='synonyms')
return results['InformationList']['Information'][0]['Synonym'] if results else []

@memoized_property
def sids(self):
"""Requires an extra request. Result is cached."""
Expand Down

0 comments on commit 9c49b42

Please sign in to comment.