Skip to content

Commit

Permalink
change cache decorator function signature for proper documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
theOehrly committed Mar 13, 2021
1 parent c05aa4f commit 52ff4b5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions fastf1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def api_request_wrapper(cls, func):
Returns:
The wrapped function
"""
def cached_api_request(api_path, **kwargs):
def cached_api_request(api_path, response=None, livedata=None):
if cls._CACHE_DIR:
# caching is enabled, extend the cache dir path using the api path
cache_dir_path = os.path.join(cls._CACHE_DIR, api_path[8:]) # remove leading '/static/' from api path
Expand All @@ -160,7 +160,7 @@ def cached_api_request(api_path, **kwargs):

else: # created with different version or force renew --> download again and update
logging.info(f"Updating cache for {str(func.__name__)}...")
data = func(api_path, **kwargs)
data = func(api_path, response=None, livedata=None)
if data is not None:
new_cached = {'version': cls._API_CORE_VERSION, 'data': data}
pickle.dump(new_cached, open(cache_file_path, 'wb'))
Expand All @@ -172,7 +172,7 @@ def cached_api_request(api_path, **kwargs):

else: # cached data does not yet exist for this request, try to download and create cache
logging.info("No cached data found. Downloading...")
data = func(api_path, **kwargs)
data = func(api_path, response=None, livedata=None)
if data is not None:
new_cached = {'version': cls._API_CORE_VERSION, 'data': data}
pickle.dump(new_cached, open(cache_file_path, 'wb'))
Expand All @@ -190,7 +190,7 @@ def cached_api_request(api_path, **kwargs):

cls._has_been_warned = True

return func(api_path, **kwargs)
return func(api_path, response=None, livedata=None)

wrapped = cached_api_request
wrapped.__doc__ = func.__doc__ # necessary to make docstrings work
Expand Down

0 comments on commit 52ff4b5

Please sign in to comment.