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

Feat: pyright helps dify remove dead var and func #16741

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

hyongtao-db
Copy link
Contributor

@hyongtao-db hyongtao-db commented Mar 25, 2025

Summary

I propose to use pyright to detect unused functions and code automatically.
This is the config file pyrightconfig.json.

{
  "reportUnusedVariable": "error",
  "reportUnusedFunction": "error",
  "reportUnusedClass": "error",
  "reportMissingImports": "none",
  "reportUndefinedVariable": "none",
  "typeCheckingMode": "off"
}

Tip

Close issue syntax: Fixes #<issue number> or Resolves #<issue number>, see documentation for more details.

Screenshots

Before After
... ...

Checklist

Important

Please review the checklist below before submitting your pull request.

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. 💪 enhancement New feature or request labels Mar 25, 2025
@crazywoola crazywoola marked this pull request as draft March 25, 2025 08:49
@hyongtao-db hyongtao-db changed the title [WIP] Pyright helps dify remove dead var and func Pyright helps dify remove dead var and func Mar 25, 2025
@hyongtao-db hyongtao-db marked this pull request as ready for review March 25, 2025 10:02
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Mar 25, 2025
@crazywoola crazywoola requested a review from laipz8200 March 26, 2025 06:51
@hyongtao-db hyongtao-db changed the title Pyright helps dify remove dead var and func Feat: pyright helps dify remove dead var and func Mar 28, 2025
Copy link
Member

@laipz8200 laipz8200 left a comment

Choose a reason for hiding this comment

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

I have commented on some areas that need modifications, not all of them. Please check all similar issues.

api/commands.py Outdated
@@ -561,7 +561,7 @@ def old_metadata_migration():
for document in documents:
if document.doc_metadata:
doc_metadata = document.doc_metadata
for key, value in doc_metadata.items():
for key, _ in doc_metadata.items():
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for key, _ in doc_metadata.items():
for key in doc_metadata:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done at commit 86aed5b

@@ -122,7 +122,7 @@ def post(self):
language = "en-US"
try:
account = AccountService.get_user_through_email(args["email"])
except AccountRegisterError as are:
except AccountRegisterError:
raise AccountInFreezeError()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
raise AccountInFreezeError()
raise AccountInFreezeError() from are

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done at commit c5710e8

@@ -153,7 +153,7 @@ def post(self):
language = "en-US"
try:
account = AccountService.get_user_through_email(args["email"])
except AccountRegisterError as are:
except AccountRegisterError:
raise AccountInFreezeError()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
raise AccountInFreezeError()
raise AccountInFreezeError() from are

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done at commit c5710e8

@@ -175,7 +175,7 @@ def decorated(*args, **kwargs):
if utm_info:
utm_info_dict: dict = json.loads(utm_info)
OperationService.record_utm(current_user.current_tenant_id, utm_info_dict)
except Exception as e:
except Exception:
pass
Copy link
Member

Choose a reason for hiding this comment

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

I think it's better to print logs here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done at commit ccb4072

@laipz8200 laipz8200 requested a review from JohnJyong April 7, 2025 03:21
@laipz8200
Copy link
Member

laipz8200 commented Apr 7, 2025

@JohnJyong
Hi, can you review part of the dataset?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants