toddrob99 / MLB-StatsAPI

Python wrapper for MLB Stats API
GNU General Public License v3.0
539 stars 100 forks source link

Check if highlights exist gracefully #102

Closed DatGuy1 closed 1 year ago

DatGuy1 commented 1 year ago

Currently, the highlights object can be None, such as here:

>>> r = get(
...         "schedule",
...         {
...             "sportId": 1,
...             "gamePk": gamePk,
...             "hydrate": "game(content(highlights(highlights)))",
...             "fields": "dates,date,games,gamePk,content,highlights,items,headline,type,value,title,description,duration,playbacks,name,url",
...         },
...     )
>>>
>>> r
{'dates': [{'date': '2023-02-25', 'games': [{'gamePk': 719386, 'content': {'highlights': {'highlights': None}}}]}]}

The change both checks for it gracefully rather than throwing a TypeError: 'NoneType' object is not subscriptable and returns an empty list rather than an empty string, to match the other return values

toddrob99 commented 1 year ago

This fix is published in v1.6.1