Skip to content

[Chore/Refactor] remove redundant-cast #24645

Closed

Description

@asukaminato0721

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for refactoring, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Description

Many are leaving redundant-cast.

how to do it:

go to a check log like https://github.com/langgenius/dify/actions/runs/17258598012/job/48975128610 (you can choose any related log)

search for is the same type as in pyrefly check, and fix them.

example #24646

Motivation

Clean code.

Additional Context

https://pyrefly.org/en/docs/error-kinds/#redundant-cast

Activity

  1. Gnomeek commented on Aug 28, 2025

    @Gnomeek
    Contributor

    I can do this.

  2. asukaminato0721 commented on Feb 23, 2026

    @asukaminato0721
    ContributorAuthor
     WARN Redundant cast: `int` is the same type as `int` [redundant-cast]
      --> core/ops/tencent_trace/utils.py:26:20
       |
    26 |         return cast(int, uuid_obj.int)
       |                    -------------------
       |
     WARN Redundant cast: `int` is the same type as `int` [redundant-cast]
      --> core/ops/tencent_trace/utils.py:55:82
       |
    55 |             trace_id = int(trace_id_str, 16) if len(trace_id_str) == 32 else cast(int, uuid.UUID(trace_id_str).int)
       |                                                                                  ----------------------------------
    
  3. asukaminato0721 commented on Feb 23, 2026

    @asukaminato0721
    ContributorAuthor

    @dosu what do you think

  4. dosubot commented on Feb 23, 2026

    @dosubot

    This looks like a good refactoring issue! The casts are indeed redundant.

    In Python's uuid module, UUID.int is already typed as int (it returns the UUID as a 128-bit integer). Since typing.cast() is a no-op at runtime and only serves as a hint to static type checkers, wrapping an already-int value in cast(int, ...) provides no benefit.

    Both lines can be simplified:

    • Line 26: return uuid_obj.int
    • Line 55: uuid.UUID(trace_id_str).int

    @Gnomeek's offer to take this on sounds great — it's a clean, low-risk cleanup that improves code clarity.

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about dify with Dosu

  5. added
    good first issue
    🙏 help wanted
    on Mar 30, 2026
  6. majiayu000 commented on Mar 31, 2026

    @majiayu000
    Contributor

    I’m picking up a small follow-up batch for this issue: remove remaining safe redundant-cast warnings (starting with api/core/ops/tencent_trace/utils.py) and run pyrefly + type checks before opening a PR.

  7. majiayu000 commented on Mar 31, 2026

    @majiayu000
    Contributor

    Quick update after verification on current upstream/main: I ran uv run --directory api --dev pyrefly check and searched diagnostics for redundant-cast, but found no remaining redundant-cast warnings to fix in this branch snapshot. This one appears to be effectively resolved by prior cleanup PRs.

  8. dosubot commented on Mar 31, 2026

    @dosubot

    @crazywoola The user is continuing work on this by removing remaining safe redundant-cast warnings in api/core/ops/tencent_trace/utils.py and plans to run pyrefly and type checks before submitting a PR. Could you please assist them with this follow-up?

  9. asukaminato0721 commented on Apr 1, 2026

    @asukaminato0721
    ContributorAuthor

    @dosu are there any redundant-cast now?

  10. dosubot commented on Apr 1, 2026

    @dosubot

    Based on a codebase search, it looks like @majiayu000's finding is correct — the obvious redundant-cast warnings (like the ones in tencent_trace/utils.py) have already been cleaned up by prior PRs, most notably PR #24807 (26+ files) and PR #33056 (which specifically removed the cast(int, uuid_obj.int) calls from the trace utilities).

    The remaining 100+ typing.cast usages across the codebase are mostly legitimate — things like type narrowing after JSON deserialization, handling SQLAlchemy's Any return types, and complex control flow where static checkers can't infer the narrowed type [1] [2]. The project also has reportUnnecessaryCast enabled in pyrightconfig [3], which should prevent new redundant casts from slipping in.

    So this issue looks effectively resolved. If pyrefly reports no redundant-cast warnings on the current main branch, there's nothing left to fix here.

    To reply, just mention @dosu.


    Docs are dead. Just use Dosu.

    Leave Feedback Ask Dosu about dify

  11. 14 remaining items

  12. Keviniscool-boy commented on Oct 11, 2026

    @Keviniscool-boy
    Contributor

    Hi, taking another slice of this issue: commands/test_reset_encrypt_key_pair.py — bring the file under strict Pyrefly checks and remove its entry from tests/unit_tests/pyrefly.toml, following #43840 (same pattern). PR to follow shortly.

  13. CodeAlex52 commented on Oct 11, 2026

    @CodeAlex52
    Contributor

    Hi, I would like to take the libs/test_workspace_permission.py slice: bring the file under strict Pyrefly checks and remove its entry from tests/unit_tests/pyrefly.toml, following the pattern of #43798 / #43840. PR to follow shortly.

  14. Keviniscool-boy commented on Oct 11, 2026

    @Keviniscool-boy
    Contributor

    Claiming commands/test_clean_expired_messages.py — PR: #43883 (10 diagnostics fixed: 4 not-callable, 4 unannotated-return, 2 implicit-any-type-argument).

  15. KissFeng commented on Oct 15, 2026

    @KissFeng
    Contributor

    Hi @asukaminato0721, I would like to help with this! I will clean up the redundant casts in api/core/tools/mcp_tool/tool.py.

  16. github-actions commented on Oct 30, 2026

    @github-actions
    Contributor

    Closed due to inactivity. If you have any questions, you can reopen it.

  17. added
    no-issue-activity
    on Oct 30, 2026
  18. louisss1016 commented on Nov 2, 2026

    @louisss1016

    I'd like to take only api/tests/unit_tests/core/logging/test_filters.py as a strict-Pyrefly follow-up, leaving the existing claimed modules untouched. The scope is typed real LogRecord fixtures and callbacks, plus removal of this file's strict-mode exclusion, preserving the logging, OpenTelemetry and Flask authentication regression coverage.

    Update: I am releasing this scope for now because the local Linux filesystem failed before I could complete the full validation. No source changes or PR have been submitted for this slice. The unchanged file produces 29 strict diagnostics, but the complete runtime baseline is not available.

  19. removed
    no-issue-activity
    on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

good first issue🙏 help wanted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions