Repository navigation
refactor(api): enable strict typing for variable truncator and plugin error test files - #44889
Conversation
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-10-28 12:05:46.111285821 +0000
+++ /tmp/pyrefly_pr.txt 2026-10-28 12:05:34.635200849 +0000
@@ -5878,14 +5878,6 @@
--> tests/unit_tests/services/enterprise/test_plugin_manager_service.py:59:25
ERROR Argument `None` is not assignable to parameter `response` with type `Response` in function `httpx._exceptions.HTTPStatusError.__init__` [bad-argument-type]
--> tests/unit_tests/services/enterprise/test_plugin_manager_service.py:60:26
-ERROR Object of class `FromClause` has no attribute `create` [missing-attribute]
- --> tests/unit_tests/services/errors/test_plugin.py:55:13
-ERROR Object of class `NoneType` has no attribute `version` [missing-attribute]
- --> tests/unit_tests/services/errors/test_plugin.py:85:16
-ERROR Object of class `NoneType` has no attribute `version` [missing-attribute]
- --> tests/unit_tests/services/errors/test_plugin.py:103:16
-ERROR Object of class `NoneType` has no attribute `credential_id` [missing-attribute]
- --> tests/unit_tests/services/errors/test_plugin.py:570:16
ERROR Argument `str` is not assignable to parameter `type` with type `Literal['basic', 'bearer', 'custom'] | None` in function `services.entities.external_knowledge_entities.external_knowledge_entities.AuthorizationConfig.__init__` [bad-argument-type]
--> tests/unit_tests/services/knowledge/external/test_service.py:116:60
ERROR Argument `str` is not assignable to parameter `type` with type `Literal['api-key', 'no-auth']` in function `services.entities.external_knowledge_entities.external_knowledge_entities.Authorization.__init__` [bad-argument-type]
@@ -6152,14 +6144,6 @@
--> tests/unit_tests/services/test_snippet_service.py:1035:9
ERROR Object of class `NoneType` has no attribute `use_count` [missing-attribute]
--> tests/unit_tests/services/test_snippet_service.py:1090:12
-ERROR Cannot set item in `dict[str, int]` [unsupported-operation]
- --> tests/unit_tests/services/test_variable_truncator.py:147:35
-ERROR Argument `list[File]` is not assignable to parameter `value` with type `list[object]` in function `services.variable_truncator.VariableTruncator._truncate_array` [bad-argument-type]
- --> tests/unit_tests/services/test_variable_truncator.py:724:48
-ERROR Argument `list[File]` is not assignable to parameter `value` with type `list[object]` in function `services.variable_truncator.VariableTruncator._truncate_array` [bad-argument-type]
- --> tests/unit_tests/services/test_variable_truncator.py:736:48
-ERROR Argument `list[File]` is not assignable to parameter `value` with type `list[object]` in function `services.variable_truncator.VariableTruncator._truncate_array` [bad-argument-type]
- --> tests/unit_tests/services/test_variable_truncator.py:751:48
ERROR Argument `list[FromClause]` is not assignable to parameter `tables` with type `Sequence[Table] | None` in function `sqlalchemy.sql.schema.MetaData.create_all` [bad-argument-type]
--> tests/unit_tests/services/test_workflow_collaboration_service.py:47:56
WARN Call to deprecated overload `contextlib.contextmanager` [deprecated]
|
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #44889 +/- ##
=======================================
Coverage 89.52% 89.52%
=======================================
Files 6009 6009
Lines 376843 376843
Branches 76238 76238
=======================================
+ Hits 337380 337387 +7
+ Misses 33465 33457 -8
- Partials 5998 5999 +1
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:
|
… error test files
…r tests The declarative `__table__` is typed as `FromClause`, and `Session.get` plus the cached-version lookup are optional. Narrow them with real assertions instead of suppressing the diagnostics.
8004744 to
7625b7e
Compare
|
Rebased onto The |
Review follow-up: the `obj_with_files: dict[str, object]` annotation was only there to satisfy the `dict[str, object]` overload. Passing the literal at the call site does the same job without an annotation. Dropping the annotation while keeping the local variable does not type-check: pyrefly infers `dict[str, File]`, and `dict` is invariant in its value type, so it matches neither `dict[str, object]` nor `list[object]` (no-matching-overload). At the call site the parameter type flows into the literal instead. Verified: pyrefly 1.4.0 with preset=strict and infer-with-first-use=true reports 0 diagnostics on both shapes; ruff check/format produce no new findings on this file compared with the previous revision.
|
Local: |
Summary
Enable strict pyrefly checking for the variable-truncator and plugin-error test files by removing them from the strict-mode exclusion list and fixing the resulting diagnostics:
VariableTruncatorfixtures,MagicMockfor patched collaborators,Callable[..., None]forconfig_overrides,Filefor the parametrized file fixture,PluginInstallationScopefor the scope cases).dict[str, object]/list[object]locals with explicit narrowing in the deep-nesting loop) so value-type invariance is satisfied without loosening the tested API signatures.@override-consistent signatures and typed containers for the plugin-service fakes.Verification
pyrefly checkwith the unit-test strict config: 0 error-level diagnostics for both files.ruff format+ruff check: clean.scripts/check_no_new_test_doubles.py --base-rev main: no new test doubles.services/files), so runtime coverage relies on CI.