mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-26 08:05:55 +03:00
[PR #991] [MERGED] Changed cache_handler.py to utilize Python's Context Management Protocol #1113
Labels
No labels
api-bug
bug
dependencies
documentation
duplicate
enhancement
external-ide
headless-mode
implicit-grant-flow
invalid
missing-endpoint
pr-welcome
private-api
pull-request
question
spotipy3
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotipy#1113
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/spotipy-dev/spotipy/pull/991
Author: @508chris
Created: 6/12/2023
Status: ✅ Merged
Merged: 1/22/2025
Merged by: @stephanebruckert
Base:
master← Head:508chris-branch📝 Commits (10+)
87e4c65Changed CacheHandler methods get_cached_token and save_token_to_cache to utilize pythons context management protocol to open and close files, instead of opening and closing manually. More information specified in the pull request.cf9d89dUpdated changelog53adef2Merge branch 'master' into 508chris-branch78449baBack to IOError73ce65fUpdate docs forcurrent_user_top_artists(#1171)5799ba3Changed CacheHandler methods get_cached_token and save_token_to_cache to utilize pythons context management protocol to open and close files, instead of opening and closing manually. More information specified in the pull request.5505f33Updated changelogd1c1294Fixed cachehandler mocking in unit tests.ee47dadMerge branch 'master' into 508chris-branche830607pep8📊 Changes
7 files changed (+121 additions, -64 deletions)
View changed files
📝
.github/workflows/integration_tests.yml(+0 -1)📝
.github/workflows/unit_tests.yml(+0 -1)📝
CHANGELOG.md(+51 -28)➖
examples(+0 -1)📝
spotipy/cache_handler.py(+8 -8)📝
spotipy/util.py(+1 -0)📝
tests/unit/test_oauth.py(+61 -25)📄 Description
I changed two methods within the CacheHandler class, get_cached_token and save_token_to_cache. Instead of opening and closing files manually, I updated these methods to use Python's "with" statement to keep up with good practice in Python programming.
This will also alleviate any errors that occur before the file is closed which would result in allocated resources.
Using the with statement, it simplifies the code as well as provides more reliability to the code base.
I also added an except clause to the get_cached_token method to handle any json decode errors.
Let me know if you have any questions at all.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.