Repository navigation
Conversation
asukaminato0721
left a comment
There was a problem hiding this comment.
1 inline suggestion at e50af88776, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong.
dify-codereview
|
|
||
|
|
||
| def timestamp_value(timestamp): | ||
| def timestamp_value(timestamp: Any) -> int: |
There was a problem hiding this comment.
Please use the precise type here, not object / Any: e.g. -> str, -> Session, Callable[...]; for a parametrized test, the union of the case types (or a type alias for it); for __exit__, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None.
dify-codereview · precise-types (concrete-type) Learned from an earlier review. Reply here if this is wrong.
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-11-19 06:01:25.474684438 +0000
+++ /tmp/pyrefly_pr.txt 2026-11-19 06:01:08.014449341 +0000
@@ -3766,6 +3766,52 @@
--> tests/unit_tests/core/mcp/server/test_streamable_http.py:390:16
ERROR Argument `Literal['invalid_mode']` is not assignable to parameter `mode` with type `AppMode | SQLCoreOperations[AppMode]` in function `models.model.App.__init__` [bad-argument-type]
--> tests/unit_tests/core/mcp/server/test_streamable_http.py:609:18
+ERROR `MockNotificationParams` is not assignable to upper bound `NotificationParams | dict[str, Any] | None` of type variable `NotificationParamsT` [bad-specialization]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:51:24
+ERROR `MockRequest` is not assignable to upper bound `ClientRequest | ServerRequest` of type variable `SendRequestT` [bad-specialization]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:64:19
+ERROR `MockNotification` is not assignable to upper bound `ClientNotification | ServerNotification` of type variable `SendNotificationT` [bad-specialization]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:64:19
+ERROR `MockResult` is not assignable to upper bound `ClientResult | ServerResult` of type variable `SendResultT` [bad-specialization]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:64:19
+ERROR `ReceiveRequest` is not assignable to upper bound `ClientRequest | ServerRequest` of type variable `ReceiveRequestT` [bad-specialization]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:64:19
+ERROR `ReceiveNotification` is not assignable to upper bound `ClientNotification | ServerNotification` of type variable `ReceiveNotificationT` [bad-specialization]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:64:19
+ERROR Argument `object` is not assignable to parameter `read_stream` with type `Queue[Unknown]` in function `core.mcp.session.base_session.BaseSession.__init__` [bad-argument-type]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:66:26
+ERROR Argument `object` is not assignable to parameter `write_stream` with type `Queue[Unknown]` in function `core.mcp.session.base_session.BaseSession.__init__` [bad-argument-type]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:66:26
+ERROR Argument `object` is not assignable to parameter `receive_request_type` with type `type[ReceiveRequest]` in function `core.mcp.session.base_session.BaseSession.__init__` [bad-argument-type]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:66:26
+ERROR Argument `object` is not assignable to parameter `receive_notification_type` with type `type[ReceiveNotification]` in function `core.mcp.session.base_session.BaseSession.__init__` [bad-argument-type]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:66:26
+ERROR Argument `object` is not assignable to parameter `read_timeout_seconds` with type `timedelta | None` in function `core.mcp.session.base_session.BaseSession.__init__` [bad-argument-type]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:66:26
+ERROR Class member `MockSession._received_request` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:71:9
+ERROR Class member `MockSession._received_notification` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:74:9
+ERROR Class member `MockSession._handle_incoming` overrides parent class `BaseSession` in an inconsistent manner [bad-override-param-name]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:77:9
+ERROR Class member `MockSession._handle_incoming` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:77:9
+ERROR `ReceiveRequest` is not assignable to upper bound `ClientRequest | ServerRequest` of type variable `ReceiveRequestT` [bad-specialization]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:93:33
+ERROR `MockResult` is not assignable to upper bound `ClientResult | ServerResult` of type variable `SendResultT` [bad-specialization]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:93:33
+ERROR `ReceiveRequest` is not assignable to upper bound `ClientRequest | ServerRequest` of type variable `ReceiveRequestT` [bad-specialization]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:120:33
+ERROR `MockResult` is not assignable to upper bound `ClientResult | ServerResult` of type variable `SendResultT` [bad-specialization]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:120:33
+ERROR Object of class `NoneType` has no attribute `result` [missing-attribute]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:148:5
+ERROR Object of class `NoneType` has no attribute `done` [missing-attribute]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:149:12
+ERROR `ReceiveRequest` is not assignable to upper bound `ClientRequest | ServerRequest` of type variable `ReceiveRequestT` [bad-specialization]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:594:26
+ERROR `ReceiveNotification` is not assignable to upper bound `ClientNotification | ServerNotification` of type variable `ReceiveNotificationT` [bad-specialization]
+ --> tests/unit_tests/core/mcp/session/test_base_session.py:594:26
ERROR Argument `(c: Unknown, p: Unknown) -> None` is not assignable to parameter `sampling_callback` with type `SamplingFnT | None` in function `core.mcp.session.client_session.ClientSession.__init__` [bad-argument-type]
--> tests/unit_tests/core/mcp/session/test_client_session.py:570:58
ERROR Argument `(c: Unknown) -> None` is not assignable to parameter `list_roots_callback` with type `ListRootsFnT | None` in function `core.mcp.session.client_session.ClientSession.__init__` [bad-argument-type]
@@ -5181,6 +5227,18 @@
--> tests/unit_tests/services/test_agent_config_service.py:1180:12
ERROR Type `object` is not iterable [not-iterable]
--> tests/unit_tests/services/test_agent_config_service.py:1216:38
+ERROR Argument `AppMode | str` is not assignable to parameter `mode` with type `AppMode | SQLCoreOperations[AppMode]` in function `models.model.App.__init__` [bad-argument-type]
+ --> tests/unit_tests/services/test_app_generate_service.py:84:14
+ERROR Class member `_TrackingRateLimit.exit` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
+ --> tests/unit_tests/services/test_app_generate_service.py:869:21
+ERROR Class member `_TrackingRateLimit.exit` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
+ --> tests/unit_tests/services/test_app_generate_service.py:905:21
+ERROR Class member `_TrackingRateLimit.exit` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
+ --> tests/unit_tests/services/test_app_generate_service.py:939:21
+ERROR Argument `_FakeStreams` is not assignable to parameter `redis_client` with type `Redis[Unknown] | RedisCluster[Unknown]` in function `libs.broadcast_channel.redis.streams_channel.StreamsBroadcastChannel.__init__` [bad-argument-type]
+ --> tests/unit_tests/services/test_app_generate_service.py:1275:40
+ERROR Argument `_FakeRedisClient` is not assignable to parameter `redis_client` with type `Redis[Unknown] | RedisCluster[Unknown]` in function `libs.broadcast_channel.redis.pubsub_channel.BroadcastChannel.__init__` [bad-argument-type]
+ --> tests/unit_tests/services/test_app_generate_service.py:1293:38
ERROR Argument `str` is not assignable to parameter `freeze_type` with type `Literal['', 'email_domain_suspended', 'freeze']` in function `services.billing_client.saas.CheckAccountInFreezeReply.model_construct` [bad-argument-type]
--> tests/unit_tests/services/test_billing_service.py:373:87
ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `ConversationStatus | SQLCoreOperations[ConversationStatus]` in function `models.model.Conversation.__init__` [bad-argument-type]
|
Pyrefly Type Coverage
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #46709 +/- ##
==========================================
+ Coverage 89.88% 90.12% +0.24%
==========================================
Files 6247 6365 +118
Lines 391170 403226 +12056
Branches 78443 79957 +1514
==========================================
+ Hits 351619 363426 +11807
+ Misses 33446 33398 -48
- Partials 6105 6402 +297
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
I will close this PR because it can be easily merged into #46711. |
Problem
Several utility and validation functions in
api/libs/helper.pywere missing type hints for their parameters and return types. This reduces code readability and prevents static type checkers from catching type-related bugs.The following functions/methods lacked type hints:
email(email)run(script)timestamp_value(timestamp)timezone(timezone_string)generate_string(n)StrLen.__init__andStrLen.__call__DatetimeString.__init__andDatetimeString.__call__Solution
Added appropriate type hints to all listed functions and methods:
Also added type hints to
StrLenandDatetimeStringclass constructors and__call__methods.Testing
Anyis already imported in the file (used by other functions)