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

chore: run pyupgrade #968

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

chore: run pyupgrade #968

wants to merge 2 commits into from

Conversation

tushar-composio
Copy link
Collaborator

@tushar-composio tushar-composio commented Dec 9, 2024

Ran pyupgrade ./python/composio --py38-plus


Important

Modernize Python codebase to Python 3.8+ using pyupgrade, updating syntax and simplifying code across multiple files.

  • Syntax Modernization:
    • Replaced set([...]) with {...} in add.py, file.py, and lsp_helper.py.
    • Replaced super(ClassName, self) with super() in catch_all_exceptions.py.
    • Replaced subprocess.PIPE with capture_output=True in api.py, shell.py, and computer.py.
    • Removed encoding="utf-8" from open() calls where default is sufficient in grep_utils.py, queries/__init__.py, and repomap.py.
    • Replaced IOError with OSError in git_repo_tree.py and grep.py.
  • Miscellaneous:
    • Minor refactoring and simplification of list comprehensions and tuple unpacking in abs.py and lsp_helper.py.

This description was created by Ellipsis for ee75893. It will automatically update as commits are pushed.

Copy link

vercel bot commented Dec 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
composio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 9, 2024 9:49am

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Reviewed everything up to c7d1769 in 28 seconds

More details
  • Looked at 434 lines of code in 20 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. python/composio/server/api.py:262
  • Draft comment:
    The change from stdout=subprocess.PIPE, stderr=subprocess.PIPE to capture_output=True is appropriate and aligns with modern Python practices. This change is also applied in python/composio/tools/local/anthropic_computer_use/actions/computer.py and python/composio/tools/env/host/shell.py.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The use of capture_output=True in subprocess.run is a more concise and modern approach introduced in Python 3.7, replacing the older method of separately specifying stdout=subprocess.PIPE and stderr=subprocess.PIPE. This change is appropriate and aligns with the intent of the PR to modernize the code for Python 3.8+.
2. python/composio/cli/add.py:289
  • Draft comment:
    The change from using a list comprehension to a set comprehension is appropriate and improves performance by directly creating a set. This change is also applied in python/composio/tools/env/filemanager/file.py.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The change from using a list comprehension to a set comprehension is appropriate here. It simplifies the code and improves performance by directly creating a set, which is the desired data structure. This change is also applied in python/composio/tools/env/filemanager/file.py.

Workflow ID: wflow_7EekfqhVPTvtkIEN


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link

github-actions bot commented Dec 9, 2024

This comment was generated by github-actions[bot]!

JS SDK Coverage Report

📊 Coverage report for JS SDK can be found at the following URL:
https://pub-92e668239ab84bfd80ee07d61e9d2f40.r2.dev/coverage-12233034925/coverage/index.html

📁 Test report folder can be found at the following URL:
https://pub-92e668239ab84bfd80ee07d61e9d2f40.r2.dev/html-report-12233034925/html-report/report.html

@@ -210,12 +209,12 @@ def setup(self) -> None:
def _send(self, buffer: str, stdin: t.Optional[str] = None) -> None:
"""Send buffer to shell."""
if stdin is None:
self.channel.sendall(f"{buffer}\n".encode("utf-8"))
self.channel.sendall(f"{buffer}\n".encode())
Copy link
Collaborator

Choose a reason for hiding this comment

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

While removing utf-8 from .encode() is generally safe as it's the default encoding in Python 3, in network communication contexts (like SSH) it's often better to be explicit about encodings to prevent potential issues with different system locales or SSH implementations. Consider keeping the explicit encode('utf-8') for network-related operations.

@shreysingla11
Copy link
Collaborator

Code Review Summary

Overall, the changes look good and improve code modernization. Here's a detailed assessment:

Positive Changes

✅ Modernized Python syntax using pyupgrade
✅ Simplified subprocess calls using capture_output=True
✅ Improved code readability with set/dict literals
✅ Modernized super() calls
✅ Removed redundant encoding parameters

Areas for Improvement

  1. Network Communication:

    • Consider keeping explicit UTF-8 encoding in SSH-related operations
    • Network protocols benefit from explicit encoding specifications
  2. Exception Handling:

    • Some generic exception handlers could be more specific
    • Consider using precise exceptions like FileNotFoundError where applicable
  3. File Operations:

    • Consider using pathlib consistently across the codebase
    • Some file operations could benefit from context-specific error handling

Risk Assessment

🟢 Low Risk: Most changes are syntactic improvements
🟡 Medium Risk: Encoding changes in network communication

Verdict

The PR is generally good and improves code quality. The changes are well-structured and consistent. Recommend merging after addressing the comments about encoding in network operations and exception handling specificity.

Rating: 8/10 - Good improvements with minor suggestions for robustness.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on ee75893 in 14 seconds

More details
  • Looked at 37 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. python/composio/tools/env/docker/scripts/__init__.py:124
  • Draft comment:
    The change in indentation for the ValueError message is unnecessary and should be reverted to maintain consistency with the rest of the codebase.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The change in indentation for the ValueError message in get_shell_env function is unnecessary and does not improve readability. It should be reverted to maintain consistency with the rest of the codebase.

Workflow ID: wflow_3enKyOvrvwEJd2Ci


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

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.

2 participants