Skip to content

fix(types): widen ToolProviderApiEntity icon to include EmojiIconDict#34560

Open
xr843 wants to merge 6 commits intolanggenius:mainfrom
xr843:fix/emoji-icon-dict-typing
Open

fix(types): widen ToolProviderApiEntity icon to include EmojiIconDict#34560
xr843 wants to merge 6 commits intolanggenius:mainfrom
xr843:fix/emoji-icon-dict-typing

Conversation

@xr843
Copy link
Copy Markdown
Contributor

@xr843 xr843 commented Apr 5, 2026

Summary

Follow-up to #34380 per @asukaminato0721's suggestion that the remaining pyrefly type errors "can fix it in another pr."

Pyrefly flags two type errors at services/tools/tools_transform_service.py:88/92:

ERROR `str | EmojiIconDict` is not assignable to attribute `icon` with type `Mapping[str, str] | str` [bad-assignment]
  --> services/tools/tools_transform_service.py:88:33
ERROR `str | EmojiIconDict` is not assignable to attribute `icon_dark` with type `Mapping[str, str] | str` [bad-assignment]
  --> services/tools/tools_transform_service.py:92:42

EmojiIconDict is a TypedDict with specific keys (background, content), which pyrefly does not structurally treat as Mapping[str, str].

Changes

  • Move EmojiIconDict from api/core/tools/tool_manager.py to api/core/tools/entities/common_entities.py so it can be imported by api_entities.py without a circular import
  • Widen ToolProviderApiEntity.icon and .icon_dark type annotations to accept EmojiIconDict
  • Update tool_manager.py to re-import EmojiIconDict from the new location

No runtime behavior change — purely a type annotation fix.

Test plan

  • AST syntax check on all three modified files
  • CI type checks (pyrefly) should show the two errors resolved
  • Existing tests continue to pass

🤖 Generated with Claude Code

@xr843 xr843 requested a review from QuantumGhost as a code owner April 5, 2026 07:04
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Apr 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 5, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-05 07:05:54.775682329 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-05 07:05:46.277717437 +0000
@@ -305,6 +305,10 @@
    --> core/tools/workflow_as_tool/provider.py:237:26
 ERROR Returned type `dict[object, str]` is not assignable to declared return type `dict[str, Any] | None` [bad-return]
    --> core/workflow/human_input_compat.py:183:16
+ERROR `Mapping[str, str] | str | EmojiIconDict` is not assignable to variable `icon` with type `Mapping[str, str] | str | None` [bad-assignment]
+   --> core/workflow/node_runtime.py:442:20
+ERROR `Mapping[str, str] | str | EmojiIconDict` is not assignable to variable `icon_dark` with type `Mapping[str, str] | str | None` [bad-assignment]
+   --> core/workflow/node_runtime.py:443:25
 ERROR No matching overload found for function `redis.client.Redis.__init__` called with arguments: (connection_pool=ConnectionPool) [no-matching-overload]
    --> extensions/ext_redis.py:244:38
 ERROR Cannot index into `Literal['']` [bad-index]
@@ -343,6 +347,10 @@
   --> services/document_indexing_proxy/duplicate_document_indexing_task_proxy.py:15:5
 ERROR `handled_tenant_count` was assigned in the current scope before the nonlocal declaration [unknown-name]
   --> services/plugin/plugin_migration.py:81:34
+ERROR Argument `Mapping[str, str] | str | EmojiIconDict` is not assignable to parameter `icon` with type `Mapping[str, str] | str` in function `ToolTransformService.get_tool_provider_icon_url` [bad-argument-type]
+  --> services/tools/tools_transform_service.py:86:90
+ERROR Argument `Mapping[str, str] | str | EmojiIconDict` is not assignable to parameter `icon` with type `Mapping[str, str] | str` in function `ToolTransformService.get_tool_provider_icon_url` [bad-argument-type]
+  --> services/tools/tools_transform_service.py:90:94
 ERROR Object of class `dict` has no attribute `encode`
 ERROR Object of class `dict` has no attribute `encode`
 ERROR Returned type `EndUser | Unknown | None` is not assignable to declared return type `Account | EndUser` [bad-return]

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 5, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-05 11:43:30.454795760 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-05 11:43:20.626746437 +0000
@@ -305,6 +305,10 @@
    --> core/tools/workflow_as_tool/provider.py:237:26
 ERROR Returned type `dict[object, str]` is not assignable to declared return type `dict[str, Any] | None` [bad-return]
    --> core/workflow/human_input_compat.py:183:16
+ERROR `Mapping[str, str] | str | EmojiIconDict` is not assignable to variable `icon` with type `Mapping[str, str] | str | None` [bad-assignment]
+   --> core/workflow/node_runtime.py:442:20
+ERROR `Mapping[str, str] | str | EmojiIconDict` is not assignable to variable `icon_dark` with type `Mapping[str, str] | str | None` [bad-assignment]
+   --> core/workflow/node_runtime.py:443:25
 ERROR No matching overload found for function `redis.client.Redis.__init__` called with arguments: (connection_pool=ConnectionPool) [no-matching-overload]
    --> extensions/ext_redis.py:244:38
 ERROR Cannot index into `Literal['']` [bad-index]
@@ -343,6 +347,10 @@
   --> services/document_indexing_proxy/duplicate_document_indexing_task_proxy.py:15:5
 ERROR `handled_tenant_count` was assigned in the current scope before the nonlocal declaration [unknown-name]
   --> services/plugin/plugin_migration.py:81:34
+ERROR Argument `Mapping[str, str] | str | EmojiIconDict` is not assignable to parameter `icon` with type `Mapping[str, str] | str` in function `ToolTransformService.get_tool_provider_icon_url` [bad-argument-type]
+  --> services/tools/tools_transform_service.py:86:90
+ERROR Argument `Mapping[str, str] | str | EmojiIconDict` is not assignable to parameter `icon` with type `Mapping[str, str] | str` in function `ToolTransformService.get_tool_provider_icon_url` [bad-argument-type]
+  --> services/tools/tools_transform_service.py:90:94
 ERROR Object of class `dict` has no attribute `encode`
 ERROR Object of class `dict` has no attribute `encode`
 ERROR Returned type `EndUser | Unknown | None` is not assignable to declared return type `Account | EndUser` [bad-return]

@asukaminato0721
Copy link
Copy Markdown
Contributor

fix extra errors

@asukaminato0721 asukaminato0721 self-requested a review April 5, 2026 12:01
Copy link
Copy Markdown
Contributor

@asukaminato0721 asukaminato0721 left a comment

Choose a reason for hiding this comment

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

fix type errors

auto-merge was automatically disabled April 5, 2026 13:30

Head branch was pushed to by a user without write access

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Apr 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 5, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-05 13:31:01.642962011 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-05 13:30:52.325893065 +0000
@@ -305,6 +305,8 @@
    --> core/tools/workflow_as_tool/provider.py:237:26
 ERROR Returned type `dict[object, str]` is not assignable to declared return type `dict[str, Any] | None` [bad-return]
    --> core/workflow/human_input_compat.py:183:16
+ERROR Class member `DifyToolNodeRuntime.resolve_provider_icons` overrides parent class `ToolNodeRuntimeProtocol` in an inconsistent manner [bad-override]
+   --> core/workflow/node_runtime.py:417:9
 ERROR No matching overload found for function `redis.client.Redis.__init__` called with arguments: (connection_pool=ConnectionPool) [no-matching-overload]
    --> extensions/ext_redis.py:244:38
 ERROR Cannot index into `Literal['']` [bad-index]
@@ -6712,8 +6714,7 @@
     --> tests/unit_tests/services/test_workflow_service.py:2763:65
 ERROR Argument `Literal['api_key']` is not assignable to parameter `credential_type` with type `CredentialType` in function `services.tools.builtin_tools_manage_service.BuiltinToolManageService.list_builtin_provider_credentials_schema` [bad-argument-type]
   --> tests/unit_tests/services/tools/test_builtin_tools_manage_service.py:84:89
-ERROR Object of class `Mapping` has no attribute `startswith` [missing-attribute]
-   --> tests/unit_tests/services/tools/test_tools_transform_service.py:464:16
+ERROR Object of class `EmojiIconDict` has no attribute `startswith`
 ERROR Could not import `DatasetDocument` from `models.dataset` [missing-module-attribute]
    --> tests/unit_tests/services/vector_service.py:126:49
 ERROR `list[Document]` is not assignable to attribute `children` with type `list[ChildDocument] | None` [bad-assignment]

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 5, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-05 13:33:07.680953553 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-05 13:32:59.416958246 +0000
@@ -305,6 +305,8 @@
    --> core/tools/workflow_as_tool/provider.py:237:26
 ERROR Returned type `dict[object, str]` is not assignable to declared return type `dict[str, Any] | None` [bad-return]
    --> core/workflow/human_input_compat.py:183:16
+ERROR Class member `DifyToolNodeRuntime.resolve_provider_icons` overrides parent class `ToolNodeRuntimeProtocol` in an inconsistent manner [bad-override]
+   --> core/workflow/node_runtime.py:417:9
 ERROR No matching overload found for function `redis.client.Redis.__init__` called with arguments: (connection_pool=ConnectionPool) [no-matching-overload]
    --> extensions/ext_redis.py:244:38
 ERROR Cannot index into `Literal['']` [bad-index]
@@ -6712,8 +6714,7 @@
     --> tests/unit_tests/services/test_workflow_service.py:2763:65
 ERROR Argument `Literal['api_key']` is not assignable to parameter `credential_type` with type `CredentialType` in function `services.tools.builtin_tools_manage_service.BuiltinToolManageService.list_builtin_provider_credentials_schema` [bad-argument-type]
   --> tests/unit_tests/services/tools/test_builtin_tools_manage_service.py:84:89
-ERROR Object of class `Mapping` has no attribute `startswith` [missing-attribute]
-   --> tests/unit_tests/services/tools/test_tools_transform_service.py:464:16
+ERROR Object of class `EmojiIconDict` has no attribute `startswith`
 ERROR Could not import `DatasetDocument` from `models.dataset` [missing-module-attribute]
    --> tests/unit_tests/services/vector_service.py:126:49
 ERROR `list[Document]` is not assignable to attribute `children` with type `list[ChildDocument] | None` [bad-assignment]

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Apr 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 6, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-06 05:27:13.170512208 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-06 05:27:04.510474872 +0000
@@ -305,6 +305,10 @@
    --> core/tools/workflow_as_tool/provider.py:237:26
 ERROR Returned type `dict[object, str]` is not assignable to declared return type `dict[str, Any] | None` [bad-return]
    --> core/workflow/human_input_compat.py:183:16
+ERROR `Mapping[str, str] | str | EmojiIconDict` is not assignable to variable `icon` with type `Mapping[str, str] | str | None` [bad-assignment]
+   --> core/workflow/node_runtime.py:442:20
+ERROR `Mapping[str, str] | str | EmojiIconDict` is not assignable to variable `icon_dark` with type `Mapping[str, str] | str | None` [bad-assignment]
+   --> core/workflow/node_runtime.py:443:25
 ERROR No matching overload found for function `redis.client.Redis.__init__` called with arguments: (connection_pool=ConnectionPool) [no-matching-overload]
    --> extensions/ext_redis.py:244:38
 ERROR Cannot index into `Literal['']` [bad-index]
@@ -343,6 +347,10 @@
   --> services/document_indexing_proxy/duplicate_document_indexing_task_proxy.py:15:5
 ERROR `handled_tenant_count` was assigned in the current scope before the nonlocal declaration [unknown-name]
   --> services/plugin/plugin_migration.py:81:34
+ERROR Argument `Mapping[str, str] | str | EmojiIconDict` is not assignable to parameter `icon` with type `Mapping[str, str] | str` in function `ToolTransformService.get_tool_provider_icon_url` [bad-argument-type]
+  --> services/tools/tools_transform_service.py:86:90
+ERROR Argument `Mapping[str, str] | str | EmojiIconDict` is not assignable to parameter `icon` with type `Mapping[str, str] | str` in function `ToolTransformService.get_tool_provider_icon_url` [bad-argument-type]
+  --> services/tools/tools_transform_service.py:90:94
 ERROR Object of class `dict` has no attribute `encode`
 ERROR Object of class `dict` has no attribute `encode`
 ERROR Returned type `EndUser | Unknown | None` is not assignable to declared return type `Account | EndUser` [bad-return]

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Apr 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 6, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-06 09:21:01.750083172 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-06 09:20:52.103015431 +0000
@@ -6712,8 +6712,7 @@
     --> tests/unit_tests/services/test_workflow_service.py:2763:65
 ERROR Argument `Literal['api_key']` is not assignable to parameter `credential_type` with type `CredentialType` in function `services.tools.builtin_tools_manage_service.BuiltinToolManageService.list_builtin_provider_credentials_schema` [bad-argument-type]
   --> tests/unit_tests/services/tools/test_builtin_tools_manage_service.py:84:89
-ERROR Object of class `Mapping` has no attribute `startswith` [missing-attribute]
-   --> tests/unit_tests/services/tools/test_tools_transform_service.py:464:16
+ERROR Object of class `EmojiIconDict` has no attribute `startswith`
 ERROR Could not import `DatasetDocument` from `models.dataset` [missing-module-attribute]
    --> tests/unit_tests/services/vector_service.py:126:49
 ERROR `list[Document]` is not assignable to attribute `children` with type `list[ChildDocument] | None` [bad-assignment]

@xr843
Copy link
Copy Markdown
Contributor Author

xr843 commented Apr 6, 2026

Fixed the remaining type error in pyrefly diff. Narrowed the return type of get_tool_provider_icon_url to str | Mapping[str, str] (removing EmojiIconDict from return type since it's structurally a Mapping[str, str]), and used cast() for branches returning the raw icon parameter. This should eliminate the pyrefly diff showing the EmojiIconDict has no attribute startswith error change.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 6, 2026

Pyrefly Diff

No changes detected.

@xr843
Copy link
Copy Markdown
Contributor Author

xr843 commented Apr 7, 2026

Hi @asukaminato0721, all type errors have been resolved — the latest Pyrefly diff shows "No changes detected" and all CI checks are green now. Could you re-review when you get a chance? Thanks!

@asukaminato0721
Copy link
Copy Markdown
Contributor

resolve conflict

xr843 and others added 5 commits April 8, 2026 19:16
…onDict

Pyrefly flags type incompatibility at services/tools/tools_transform_service.py:88/92
where get_tool_provider_icon_url returns str | EmojiIconDict but
ToolProviderApiEntity.icon/icon_dark only accept str | Mapping[str, str].

EmojiIconDict is a TypedDict with specific keys (background, content) which
pyrefly does not structurally treat as Mapping[str, str].

Move EmojiIconDict from tool_manager.py to common_entities.py so it can be
reused by api_entities.py without introducing a circular import, then widen
the icon/icon_dark fields to accept EmojiIconDict.

Follow-up to langgenius#34380 (per reviewer suggestion).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
type-check-core fails after widening ToolProviderApiEntity.icon:
4 errors in node_runtime.resolve_provider_icons assignments and
tools_transform_service.get_tool_provider_icon_url calls.

Widen the receiving types to match.
…t is already Mapping[str, str]

EmojiIconDict extends TypedDict which is a subtype of Mapping[str, str],
so adding it explicitly to union types is redundant and causes:
- Pyrefly bad-override error (resolve_provider_icons vs protocol)
- Pyrefly missing-attribute error (EmojiIconDict has no startswith)

Revert to original Mapping[str, str] signatures — EmojiIconDict values
pass through naturally without explicit mention.
…ignments

- Restore EmojiIconDict in get_tool_provider_icon_url signature (fixes
  basedpyright bad-argument-type at call sites)
- Cast builtin_tool.icon/icon_dark to narrow type at assignment in
  resolve_provider_icons (EmojiIconDict is a TypedDict with str values,
  compatible with Mapping[str, str] but type checkers need the cast)
- Keep resolve_provider_icons return type unchanged (matches protocol)
@xr843 xr843 force-pushed the fix/emoji-icon-dict-typing branch from 5ab8b79 to b3cd330 Compare April 8, 2026 11:16
@dosubot dosubot Bot removed the size:M This PR changes 30-99 lines, ignoring generated files. label Apr 8, 2026
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Apr 8, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 8, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-08 11:17:54.392054663 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-08 11:17:45.679080713 +0000
@@ -6710,8 +6710,7 @@
     --> tests/unit_tests/services/test_workflow_service.py:2763:65
 ERROR Argument `Literal['api_key']` is not assignable to parameter `credential_type` with type `CredentialType` in function `services.tools.builtin_tools_manage_service.BuiltinToolManageService.list_builtin_provider_credentials_schema` [bad-argument-type]
   --> tests/unit_tests/services/tools/test_builtin_tools_manage_service.py:84:89
-ERROR Object of class `Mapping` has no attribute `startswith` [missing-attribute]
-   --> tests/unit_tests/services/tools/test_tools_transform_service.py:464:16
+ERROR Object of class `EmojiIconDict` has no attribute `startswith`
 ERROR Could not import `DatasetDocument` from `models.dataset` [missing-module-attribute]
    --> tests/unit_tests/services/vector_service.py:126:49
 ERROR `list[Document]` is not assignable to attribute `children` with type `list[ChildDocument] | None` [bad-assignment]

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 8, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-08 11:19:51.469349323 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-08 11:19:43.152108159 +0000
@@ -6710,8 +6710,7 @@
     --> tests/unit_tests/services/test_workflow_service.py:2763:65
 ERROR Argument `Literal['api_key']` is not assignable to parameter `credential_type` with type `CredentialType` in function `services.tools.builtin_tools_manage_service.BuiltinToolManageService.list_builtin_provider_credentials_schema` [bad-argument-type]
   --> tests/unit_tests/services/tools/test_builtin_tools_manage_service.py:84:89
-ERROR Object of class `Mapping` has no attribute `startswith` [missing-attribute]
-   --> tests/unit_tests/services/tools/test_tools_transform_service.py:464:16
+ERROR Object of class `EmojiIconDict` has no attribute `startswith`
 ERROR Could not import `DatasetDocument` from `models.dataset` [missing-module-attribute]
    --> tests/unit_tests/services/vector_service.py:126:49
 ERROR `list[Document]` is not assignable to attribute `children` with type `list[ChildDocument] | None` [bad-assignment]

@xr843
Copy link
Copy Markdown
Contributor Author

xr843 commented Apr 12, 2026

@asukaminato0721 Gentle ping — CI is all green, and the Pyrefly diff only shows pre-existing errors from the base branch (not introduced by this PR).

The type change from Mapping to EmojiIconDict is exactly what this PR intends — making the type more precise. Could you take another look when you have a moment? Thanks!

@xr843
Copy link
Copy Markdown
Contributor Author

xr843 commented Apr 27, 2026

Friendly follow-up @asukaminato0721 — it's been a couple of weeks. To recap the state: CI is fully green, the Pyrefly diff shows only pre-existing errors from the base branch (none introduced by this PR), and the change is the minimal, intentional one — narrowing ToolProviderApiEntity.icon from Mapping to the more precise EmojiIconDict union it actually accepts.\n\nIf there's a remaining concern I missed, happy to address it. Otherwise would you mind dismissing the stale review so this small typing fix can land? Thanks for your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants