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

Major Cleanup #82

Closed
wants to merge 42 commits into from
Closed

Major Cleanup #82

wants to merge 42 commits into from

Conversation

ShoGinn
Copy link

@ShoGinn ShoGinn commented Apr 25, 2024

I have tried to do the bare minimum of implementing the IDE portion.

But I did add the .gitignore and ruff editor options.

This will take a while to review, but it's worth it.

I found several possible typing situations that could cause problems, as well as getting rid of all the "Literals" and using enums.

Hopefully, it meets your coding objectives

Summary by CodeRabbit

  • New Features

    • Introduced configuration for the ruff tool in pyproject.toml to enhance code formatting.
    • Added new error handling classes and attributes in twikit for better exception management.
    • Updated twikit classes with new attributes and improved method signatures for enhanced functionality and clarity.
    • Introduced new enum classes for tweet-related types in twikit/tweet.py.
  • Bug Fixes

    • Corrected attribute types in twikit/trend.py and twikit/tweet.py to allow None values.
    • Fixed typos in exception descriptions across various modules.
  • Refactor

    • Reorganized imports and updated type annotations in twikit for improved readability and maintainability.
    • Enhanced cookie handling in HTTPClient class for better web session management.
  • Documentation

    • Updated .gitignore to include rules for various development environments and files, ensuring cleaner repositories.

remove f interpolation (unnecessary)
add/remove reaction, created get_conversation_id
self.banner typed twice
created_at_datetime cast to str
UserUnavailable was not in errors. Added
Removed the multiple response = and just returned
Moved tweet to top and moved reply parsing into the profile-conversation loop
Also add missing community from Tweet
Copy link
Contributor

coderabbitai bot commented Apr 25, 2024

Walkthrough

The update encompasses a comprehensive overhaul of the Python project, focusing on refining configurations, readability, and error management. Noteworthy changes include enhanced file exclusion rules in .gitignore, updated linting settings in pyproject.toml, improved error classes and type annotations in twikit components, and streamlined method signatures for enhanced code organization.

Changes

Files Summary of Changes
.gitignore, pyproject.toml Rules added for file exclusion and linting configurations.
twikit/... files Enhanced type annotations, refined method signatures, and improved error handling.
requirements.txt, setup.py Dependencies updated and project setup configurations revised.

🐇💻

Hop, skip, jump, the code does align,
With tweaks and types, now all so fine.
Through files and lines, the changes weave,
A tapestry of code, we joyfully conceive.
Cheers to clean code, on this bright day,
With every `commit`, our bugs shall sway!
``` 🎉

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 9fc3f91 and 2767dec.
Files selected for processing (2)
  • twikit/init.py (2 hunks)
  • twikit/utils.py (17 hunks)
Files skipped from review as they are similar to previous changes (1)
  • twikit/init.py
Additional Context Used
Ruff (3)
twikit/utils.py (3)

311-311: Too many arguments in function definition (6 > 5)


532-532: build_query is too complex (16 > 10)


532-532: Too many branches (15 > 12)

Additional comments not posted (9)
twikit/utils.py (9)

38-38: The addition of 'responsive_web_enhance_cards_enabled': False to FEATURES dictionary is consistent with the other entries. Ensure that this feature flag is utilized appropriately in the codebase where feature toggles are checked.


52-52: The addition of 'responsive_web_graphql_timeline_navigation_enabled': True to USER_FEATURES dictionary is consistent with the other entries. Ensure that this feature flag is utilized appropriately in the codebase where feature toggles are checked.


59-59: The addition of 'responsive_web_graphql_timeline_navigation_enabled': True to LIST_FEATURES dictionary is consistent with the other entries. Ensure that this feature flag is utilized appropriately in the codebase where feature toggles are checked.


68-68: The addition of 'responsive_web_graphql_skip_user_profile_image_extensions_enabled': False to COMMUNITY_NOTE_FEATURES dictionary is consistent with the other entries. Ensure that this feature flag is utilized appropriately in the codebase where feature toggles are checked.


94-94: The addition of 'responsive_web_enhance_cards_enabled': False to COMMUNITY_TWEETS_FEATURES dictionary is consistent with the other entries. Ensure that this feature flag is utilized appropriately in the codebase where feature toggles are checked.


102-102: The addition of 'responsive_web_graphql_timeline_navigation_enabled': True to JOIN_COMMUNITY_FEATURES dictionary is consistent with the other entries. Ensure that this feature flag is utilized appropriately in the codebase where feature toggles are checked.


129-129: The addition of 'responsive_web_enhance_cards_enabled': False to NOTE_TWEET_FEATURES dictionary is consistent with the other entries. Ensure that this feature flag is utilized appropriately in the codebase where feature toggles are checked.


157-157: The addition of 'responsive_web_enhance_cards_enabled': False to SIMILAR_POSTS_FEATURES dictionary is consistent with the other entries. Ensure that this feature flag is utilized appropriately in the codebase where feature toggles are checked.


185-185: The addition of 'responsive_web_enhance_cards_enabled': False to BOOKMARK_FOLDER_TIMELINE_FEATURES dictionary is consistent with the other entries. Ensure that this feature flag is utilized appropriately in the codebase where feature toggles are checked.


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.

@ShoGinn
Copy link
Author

ShoGinn commented Apr 25, 2024

I did not touch the async portion of the script...

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: 2

Out of diff range and nitpick comments (3)
twikit/community.py (2)

120-146: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [141-170]

The get_tweets method's documentation should reflect the use of TweetType enum for the tweet_type parameter.


187-193: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [190-204]

Consider adding error handling or a fallback mechanism in get_members to manage potential failures in external calls.

twikit/user.py (1)

132-138: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [135-158]

Update the documentation for get_tweets to accurately describe the use of UserTweetType.

twikit/community.py Outdated Show resolved Hide resolved
twikit/user.py Outdated Show resolved Hide resolved
ShoGinn and others added 4 commits April 25, 2024 14:00
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Also fix circular import
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: 9

Out of diff range and nitpick comments (7)
twikit/http.py (1)

Line range hint 24-24: Replace magic number 400 with a constant for better readability and maintainability.

+ HTTP_BAD_REQUEST = 400
- if status_code >= 400:
+ if status_code >= HTTP_BAD_REQUEST:
twikit/utils.py (6)

6-6: Ensure consistent spacing in import statements for better readability.


256-257: Consider using a single line for URL definitions when they fit within the line length limit to maintain consistency and readability.


Line range hint 310-310: The constructor of the Result class has too many parameters. Consider refactoring to improve maintainability.


Line range hint 505-505: Use X | Y in isinstance calls instead of (X, Y) for better readability and consistency with modern Python practices.


Line range hint 506-506: Avoid overwriting the for loop variable value by the assignment target. This can lead to unexpected behavior and bugs.


Line range hint 536-536: The build_query function is too complex. Consider simplifying it or breaking it down into smaller functions to improve readability and maintainability.

twikit/utils.py Outdated Show resolved Hide resolved
twikit/utils.py Outdated Show resolved Hide resolved
twikit/http.py Outdated Show resolved Hide resolved
twikit/http.py Show resolved Hide resolved
twikit/errors.py Outdated Show resolved Hide resolved
twikit/tweet.py Outdated Show resolved Hide resolved
Repository owner deleted a comment from coderabbitai bot Apr 26, 2024
Repository owner deleted a comment from coderabbitai bot Apr 26, 2024
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: 3

Out of diff range and nitpick comments (2)
twikit/tweet.py (1)

Line range hint 138-199: The __init__ method of the Tweet class is complex and lengthy. Consider refactoring to improve readability and maintainability.

twikit/utils.py (1)

Line range hint 536-634: The build_query function is complex and has many branches. Consider breaking it down into smaller functions or simplifying the logic.

url: str,
**kwargs
) -> httpx.Response:
async def request(self, method: str, url: str, **kwargs) -> httpx.Response:
Copy link
Contributor

Choose a reason for hiding this comment

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

Add type annotations for **kwargs to improve code clarity and type safety.

Would you like me to add these annotations for you?

Comment on lines +27 to +41
raise BadRequestError(message, headers=response.headers)
elif status_code == 401:
raise Unauthorized(message, headers=response.headers)
raise UnauthorizedError(message, headers=response.headers)
elif status_code == 403:
raise Forbidden(message, headers=response.headers)
raise ForbiddenError(message, headers=response.headers)
elif status_code == 404:
raise NotFound(message, headers=response.headers)
raise NotFoundError(message, headers=response.headers)
elif status_code == 408:
raise RequestTimeout(message, headers=response.headers)
raise RequestTimeoutError(message, headers=response.headers)
elif status_code == 429:
raise TooManyRequests(message, headers=response.headers)
raise TooManyRequestsError(message, headers=response.headers)
elif 500 <= status_code < 600:
raise ServerError(message, headers=response.headers)
else:
raise TwitterException(message, headers=response.headers)
raise TwitterError(message, headers=response.headers)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider replacing magic numbers with named constants for HTTP status codes to improve code readability and maintainability.

- if status_code == 400:
+ if status_code == HTTPStatus.BAD_REQUEST:

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.

Suggested change
raise BadRequestError(message, headers=response.headers)
elif status_code == 401:
raise Unauthorized(message, headers=response.headers)
raise UnauthorizedError(message, headers=response.headers)
elif status_code == 403:
raise Forbidden(message, headers=response.headers)
raise ForbiddenError(message, headers=response.headers)
elif status_code == 404:
raise NotFound(message, headers=response.headers)
raise NotFoundError(message, headers=response.headers)
elif status_code == 408:
raise RequestTimeout(message, headers=response.headers)
raise RequestTimeoutError(message, headers=response.headers)
elif status_code == 429:
raise TooManyRequests(message, headers=response.headers)
raise TooManyRequestsError(message, headers=response.headers)
elif 500 <= status_code < 600:
raise ServerError(message, headers=response.headers)
else:
raise TwitterException(message, headers=response.headers)
raise TwitterError(message, headers=response.headers)
raise BadRequestError(message, headers=response.headers)
elif status_code == 401:
raise UnauthorizedError(message, headers=response.headers)
elif status_code == 403:
raise ForbiddenError(message, headers=response.headers)
elif status_code == 404:
raise NotFoundError(message, headers=response.headers)
elif status_code == 408:
raise RequestTimeoutError(message, headers=response.headers)
elif status_code == 429:
raise TooManyRequestsError(message, headers=response.headers)
elif 500 <= status_code < 600:
raise ServerError(message, headers=response.headers)
else:
raise TwitterError(message, headers=response.headers)

twikit/utils.py Outdated Show resolved Hide resolved
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

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: 2

twikit/tweet.py Outdated Show resolved Hide resolved
@ShoGinn
Copy link
Author

ShoGinn commented Apr 29, 2024

@coderabbitai review

1 similar comment
@ShoGinn
Copy link
Author

ShoGinn commented Apr 29, 2024

@coderabbitai review

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 (2)
twikit/utils.py (2)

Line range hint 310-310: The constructor of the Result class has too many arguments. Consider refactoring to reduce the number of arguments, possibly by using a configuration object or additional methods for setting properties.


Line range hint 531-531: The build_query function is too complex. Consider refactoring to simplify the function, possibly by breaking it down into smaller helper functions.

twikit/tweet.py Show resolved Hide resolved
@ShoGinn
Copy link
Author

ShoGinn commented May 1, 2024

@d60 Do we plan on merging these? If not, I'll close this and stop merging branches whenever you update.

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: 0

Out of diff range and nitpick comments (3)
twikit/utils.py (3)

6-6: Consider using from __future__ import annotations to enable postponed evaluation of type annotations, which can help avoid circular imports and other issues in complex projects.


Line range hint 311-311: The __init__ method of the Result class has too many arguments. Consider refactoring to reduce complexity and improve maintainability.

- def __init__(self, results: list[T], fetch_next_result: Callable | None = None, next_cursor: str | None = None, fetch_previous_result: Callable | None = None, previous_cursor: str | None = None) -> None:
+ def __init__(self, results: list[T], fetch_next_result: Callable | None = None, cursor_info: dict[str, str | None]) -> None:
+     self.next_cursor = cursor_info.get('next_cursor')
+     self.previous_cursor = cursor_info.get('previous_cursor')

Line range hint 532-532: The build_query function is too complex and has too many branches. Consider refactoring to simplify the logic and improve readability.

- def build_query(text: str, options: SearchOptions) -> str:
+ def build_query(text: str, options: SearchOptions) -> str:
+     # Refactor to separate concerns and simplify logic

@ShoGinn ShoGinn closed this by deleting the head repository May 3, 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
Development

Successfully merging this pull request may close these issues.

None yet

1 participant