Skip to content
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

Support list of names passed to search in tvdb.py #8758

Closed
wants to merge 3 commits into from

Conversation

canepan
Copy link

@canepan canepan commented May 7, 2024

Currently, if a list is passed instead of a single str, it will fail the regex match

Fixes #

Proposed changes in this pull request:

  • process each item if a list is passed

  • PR is based on the DEVELOP branch

  • Don't send big changes all at once. Split up big PRs into multiple smaller PRs that are easier to manage and review

  • Read contribution guide

Currently, if a `list` is passed instead of a single `str`, it will fail the regex match
@BKSteve
Copy link
Collaborator

BKSteve commented May 12, 2024

What was SC doing at the time the list error was thrown?

@BKSteve BKSteve changed the base branch from master to develop May 12, 2024 10:47
names.append(re.sub(r"[. -_]", " ", test.group(1)).strip())

for attempt in set(n for n in names if n.strip()):
if isinstance(name, str):
Copy link
Contributor

@miigotu miigotu May 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this join the list like the other guessit fixes instead of just checking if it's a string?

On line 1 add:

try:
    from collections import Iterable
except (ModuleNotFoundError, ImportError):
    # Iterable moved in python3.10
    from collections.abc import Iterable

After line 106 add:

if isinstance(name, Iterable) and not isinstance(name, (str, bytes);
    name = " ".join(name)

Then remove the rest of the changes here (we know it's a string then)

Copy link
Contributor

coderabbitai bot commented May 12, 2024

Walkthrough

The update involves enhancing the search method in the TVDBIndexer class within the sickchill project. The key modification is the introduction of a type check to ensure name is a string, followed by a reorganized logic to accommodate different scenarios based on the name type, enhancing robustness and functionality.

Changes

File Path Change Summary
.../indexers/tvdb.py Added type check for name and restructured logic in search method.

Poem

🐇✨
In the code where bugs once dwelled,
A rabbit hopped, the errors quelled.
With a hop, skip, and a script rewrite,
Now the search shines ever so bright.
Cheers to code that’s clean and tight! 🎉
🐇✨


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Out of diff range and nitpick comments (1)
sickchill/show/indexers/tvdb.py (1)

Line range hint 194-194: Avoid using a bare except clause.

- except:
+ except (requests.exceptions.RequestException, requests.exceptions.HTTPError, Exception) as e:
+     logger.error(f"Error during search: {str(e)}")

Refine the exception handling to catch specific exceptions. This change will help in identifying the exact nature of errors and improve the maintainability of the code.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between a4f2166 and 87562e5.
Files selected for processing (1)
  • sickchill/show/indexers/tvdb.py (1 hunks)
Additional Context Used
Ruff (1)
sickchill/show/indexers/tvdb.py (1)

194-194: Do not use bare except

Comment on lines +145 to +146
for n in name:
result.extend(self.search(n, language, exact, indexer_id))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recursive call for list handling might lead to performance issues.

Consider using a loop to handle each item in the list within the same method instance to avoid the overhead of recursive calls. This approach can also make the method easier to debug and maintain.

break
except (requests.exceptions.RequestException, requests.exceptions.HTTPError, Exception):
logger.debug(traceback.format_exc())
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this else needs removed. We don't want to search for ["fast", "&", "furious"] each individually, we want to join that list and search for the full string.

@canepan
Copy link
Author

canepan commented May 13, 2024 via email

@miigotu
Copy link
Contributor

miigotu commented May 23, 2024

This has been fixed in #8759

@miigotu miigotu closed this May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants