-
Notifications
You must be signed in to change notification settings - Fork 707
Improvements and tweaks #649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sreckoskocilic
wants to merge
6
commits into
swar:master
Choose a base branch
from
sreckoskocilic:minor_performance_improvements
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
199b7ee
- reduce json.loads calls by introducing dict_cache
sreckoskocilic 0301526
- improve find_team_by_id and abbreviation as followup on previous co…
sreckoskocilic 76ef4ee
- remove mutable class default (dead-weight and might mislead type ch…
sreckoskocilic 7d008b4
Merge branch 'swar:master' into minor_performance_improvements
sreckoskocilic e596be4
2nd batch of improvements
sreckoskocilic 0a8449d
- fix shared headers mutation when referer is passed (copy dict inste…
sreckoskocilic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,36 @@ | ||
| import json | ||
| from typing import Any | ||
|
|
||
|
|
||
| class Endpoint: | ||
| class DataSet: | ||
| key = None | ||
| data = {} | ||
| key: str | None = None | ||
|
|
||
| def __init__(self, data=None): | ||
| def __init__(self, data: dict[str, Any] | list | None = None) -> None: | ||
| if data is None: | ||
| data = {} | ||
| self.data = data | ||
|
|
||
| def get_json(self): | ||
| def get_json(self) -> str: | ||
| return json.dumps(self.data) | ||
|
|
||
| def get_dict(self): | ||
| def get_dict(self) -> dict[str, Any] | list: | ||
| return self.data | ||
|
|
||
| def get_request_url(self): | ||
| nba_response: Any = None | ||
| data_sets: list[DataSet] | None = None | ||
|
|
||
| def get_request_url(self) -> str: | ||
| return self.nba_response.get_url() | ||
|
|
||
| def get_response(self): | ||
| def get_response(self) -> str: | ||
| return self.nba_response.get_response() | ||
|
|
||
| def get_dict(self): | ||
| def get_status_code(self) -> int: | ||
| return self.nba_response.get_status_code() | ||
|
|
||
| def get_dict(self) -> dict[str, Any]: | ||
| return self.nba_response.get_dict() | ||
|
|
||
| def get_json(self): | ||
| def get_json(self) -> str: | ||
| return self.nba_response.get_json() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the additional breakout of the exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code now checks the HTTP status code first (any >= 400) raising an Exception with the status code, before
validating JSON. This ensures HTTP errors are properly caught.