-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
fix: listrr response being treated as a dict #979
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe pull request focuses on modifying the Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/program/apis/listrr_api.py (1)
58-59
: Simplify attribute access for SimpleNamespace objects.Since the response is parsed as
SimpleNamespace
(configured inListrrRequestHandler
), you can use direct attribute access with fallback values using theor
operator for better readability.- total_pages = getattr(data, "pages", 1) - for item in getattr(data, "items", []): + total_pages = getattr(data, 'pages') or 1 + for item in getattr(data, 'items') or []:
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/program/apis/listrr_api.py
(1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
src/program/apis/listrr_api.py
60-60: Do not call getattr
with a constant attribute value. It is not any safer than normal property access.
Replace getattr
with attribute access
(B009)
63-63: Do not call getattr
with a constant attribute value. It is not any safer than normal property access.
Replace getattr
with attribute access
(B009)
64-64: Do not call getattr
with a constant attribute value. It is not any safer than normal property access.
Replace getattr
with attribute access
(B009)
🔇 Additional comments (1)
src/program/apis/listrr_api.py (1)
58-64
: Add tests for Listrr response handling.The changes modify how API responses are handled, but tests haven't been added according to the PR checklist. Please add tests to verify:
- Handling of responses with missing attributes
- Proper fallback to default values
- TMDb ID fallback scenario
Would you like me to help generate test cases for these scenarios?
🧰 Tools
🪛 Ruff (0.8.2)
60-60: Do not call
getattr
with a constant attribute value. It is not any safer than normal property access.Replace
getattr
with attribute access(B009)
63-63: Do not call
getattr
with a constant attribute value. It is not any safer than normal property access.Replace
getattr
with attribute access(B009)
64-64: Do not call
getattr
with a constant attribute value. It is not any safer than normal property access.Replace
getattr
with attribute access(B009)
imdb_id = getattr(item,"imDbId") | ||
if imdb_id: | ||
unique_ids.add(imdb_id) | ||
elif content_type == "Movies" and item.get("tmDbId"): | ||
imdb_id = self.trakt_api.get_imdbid_from_tmdb(item["tmDbId"]) | ||
elif content_type == "Movies" and getattr(item, "tmDbId"): | ||
imdb_id = self.trakt_api.get_imdbid_from_tmdb(getattr(item, "tmDbId")) |
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.
🛠️ Refactor suggestion
Use direct attribute access with proper error handling.
Since we're working with SimpleNamespace objects, we should use direct attribute access with proper error handling to catch potential AttributeError exceptions.
- imdb_id = getattr(item,"imDbId")
- if imdb_id:
- unique_ids.add(imdb_id)
- elif content_type == "Movies" and getattr(item, "tmDbId"):
- imdb_id = self.trakt_api.get_imdbid_from_tmdb(getattr(item, "tmDbId"))
+ try:
+ if item.imDbId:
+ unique_ids.add(item.imDbId)
+ elif content_type == "Movies" and item.tmDbId:
+ imdb_id = self.trakt_api.get_imdbid_from_tmdb(item.tmDbId)
+ if imdb_id:
+ unique_ids.add(imdb_id)
+ except AttributeError:
+ # Skip items that don't have the expected attributes
+ continue
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
imdb_id = getattr(item,"imDbId") | |
if imdb_id: | |
unique_ids.add(imdb_id) | |
elif content_type == "Movies" and item.get("tmDbId"): | |
imdb_id = self.trakt_api.get_imdbid_from_tmdb(item["tmDbId"]) | |
elif content_type == "Movies" and getattr(item, "tmDbId"): | |
imdb_id = self.trakt_api.get_imdbid_from_tmdb(getattr(item, "tmDbId")) | |
try: | |
if item.imDbId: | |
unique_ids.add(item.imDbId) | |
elif content_type == "Movies" and item.tmDbId: | |
imdb_id = self.trakt_api.get_imdbid_from_tmdb(item.tmDbId) | |
if imdb_id: | |
unique_ids.add(imdb_id) | |
except AttributeError: | |
# Skip items that don't have the expected attributes | |
continue |
🧰 Tools
🪛 Ruff (0.8.2)
60-60: Do not call getattr
with a constant attribute value. It is not any safer than normal property access.
Replace getattr
with attribute access
(B009)
63-63: Do not call getattr
with a constant attribute value. It is not any safer than normal property access.
Replace getattr
with attribute access
(B009)
64-64: Do not call getattr
with a constant attribute value. It is not any safer than normal property access.
Replace getattr
with attribute access
(B009)
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.
@davidemarcoli its got a point :D
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.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
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.
take note of the code rabbit suggestion
Pull Request Check List
Resolves: #975, Resolves #959
Description:
Summary by CodeRabbit
getattr()
instead of.get()
for retrieving object properties