Skip to content

refactor(api): enable strict typing for events/extensions test files - #44875

Open
shi-felix wants to merge 4 commits into
langgenius:mainfrom
shi-felix:refactor/pyrefly-strict-test-batch-9
Open

shi-felix wants to merge 4 commits into
langgenius:mainfrom
shi-felix:refactor/pyrefly-strict-test-batch-9

Conversation

@shi-felix

Copy link
Copy Markdown
Contributor

Summary

Enable strict pyrefly checking for 12 test files under tests/unit_tests/events/ and tests/unit_tests/extensions/ by removing them from the strict-mode exclusion list and fixing the resulting diagnostics:

  • Annotate fixture/parametrized parameters with their real types (AppServices, sessionmaker[Session], TracerProvider, InMemorySpanExporter, App, Account, MagicMock, sqlite3.Connection, ...).
  • Add missing -> None / -> str / Generator[...] return annotations (fixtures that yield now declare Generator).
  • Narrow optional returns from the Aliyun SLS SDK (get_query() / get_to()) with asserts, and use EndUserType.BROWSER instead of a raw string literal.
  • Annotate execute_query wrappers to mirror the real AliyunLogStore.execute_sql signature instead of unpacking **kwargs: object.
  • Keep suppression comments only where the type system cannot see runtime doubles (MagicMock call bookkeeping, protocol-abstract members that these tests never call, and the dynamic Events slots), matching existing usage in the suite.

Verification

  • pyrefly check with the unit-test strict config: 0 diagnostics for all 12 files.
  • ruff format + ruff check: clean.
  • pytest on the runnable subset (extensions/otel, extensions/logstore, ext_socketio/ext_login/ext_redis/warm_shutdown): 117 passed. The 5 errors from non_utc_host_timezone (time.tzset() is POSIX-only) reproduce on main unchanged, and tests/unit_tests/events/ cannot be collected in this local Windows sandbox (conftest environment deps hang on import), so those files are covered by CI.

@github-actions github-actions Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-11-03 02:31:35.225358687 +0000
+++ /tmp/pyrefly_pr.txt	2026-11-03 02:31:21.729246498 +0000
@@ -5616,18 +5616,6 @@
    --> tests/unit_tests/enterprise/telemetry/test_contracts.py:128:30
 ERROR Missing argument `payload` in function `enterprise.telemetry.contracts.TelemetryEnvelope.__init__` [missing-argument]
    --> tests/unit_tests/enterprise/telemetry/test_contracts.py:137:30
-ERROR Object of class `Events` has no attribute `request_start` [missing-attribute]
-  --> tests/unit_tests/events/test___init__.py:10:5
-ERROR Object of class `Events` has no attribute `request_end` [missing-attribute]
-  --> tests/unit_tests/events/test___init__.py:11:5
-ERROR Object of class `Events` has no attribute `request_start` [missing-attribute]
-  --> tests/unit_tests/events/test___init__.py:27:5
-ERROR Object of class `Events` has no attribute `request_start` [missing-attribute]
-  --> tests/unit_tests/events/test___init__.py:28:5
-ERROR Object of class `Events` has no attribute `request_start` [missing-attribute]
-  --> tests/unit_tests/events/test___init__.py:33:5
-ERROR Missing argument `session` in function `events.event_handlers.update_app_dataset_join_when_app_model_config_updated.handle` [missing-argument]
-   --> tests/unit_tests/events/test_app_event.py:193:19
 ERROR Object of class `NoneType` has no attribute `partition` [missing-attribute]
   --> tests/unit_tests/extensions/logstore/repositories/test_logstore_api_workflow_node_execution_repository.py:58:34
 ERROR `<=` is not supported between `None` and `int` [unsupported-operation]
@@ -5656,8 +5644,6 @@
   --> tests/unit_tests/extensions/test_ext_celery.py:98:18
 ERROR Object of class `Connection` has no attribute `SimpleQueue` [missing-attribute]
    --> tests/unit_tests/extensions/test_ext_celery.py:103:18
-ERROR Argument `Literal['browser']` is not assignable to parameter `type` with type `EndUserType | SQLCoreOperations[EndUserType]` in function `models.model.EndUser.__init__` [bad-argument-type]
-  --> tests/unit_tests/extensions/test_ext_login.py:53:14
 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/factories/file_factory/test_builders.py:85:58
 ERROR Object of class `NoneType` has no attribute `storage_key` [missing-attribute]

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 82.89% 82.95% +0.06%
Strict coverage 82.54% 82.61% +0.06%
Typed symbols 85,476 85,543 +67
Untyped symbols 17,723 17,656 -67
Modules 4373 4373 0

@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.77%. Comparing base (f185265) to head (72d74fa).
⚠️ Report is 22 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #44875    +/-   ##
========================================
  Coverage   89.77%   89.77%            
========================================
  Files        6238     6238            
  Lines      390615   390848   +233     
  Branches    79229    79264    +35     
========================================
+ Hits       350671   350882   +211     
- Misses      33851    33868    +17     
- Partials     6093     6098     +5     
Flag Coverage Δ
api 89.63% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@asukaminato0721 asukaminato0721 self-assigned this Oct 28, 2026

events.request_start += lambda: calls.append("start")
events.request_end += lambda: calls.append("end")
events.request_start += lambda: calls.append("start") # type: ignore[attr-defined]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we avoid so many ignore?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Cut them from 11 to 5. Reads through Events.__getattr__ resolve on their own, so only the augmented assignments still need one: += writes the slot back onto the instance, and pyrefly does not use the __getattr__ return type on the write path.

Reads through __getattr__ resolve on their own, so only the augmented
assignments that write the slot back keep the ignore.
auto-merge was automatically disabled October 30, 2026 03:45

Head branch was pushed to by a user without write access

@shi-felix
shi-felix force-pushed the refactor/pyrefly-strict-test-batch-9 branch from 075cee2 to 08ac2e8 Compare October 30, 2026 03:45
shi-felix and others added 2 commits November 2, 2026 17:52
`MagicMock()` is already assignable to the `session` parameter, so the `typing.cast("Session", ...)` was redundant and tripped the `check_no_new_cast` guard. Removing it also drops the now-unused `cast` and `Session` imports.
arguments = handler._extract_arguments(AppGenerateService.generate, **kwargs)
arguments = handler._extract_arguments(
AppGenerateService.generate,
session=MagicMock(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sqlite session

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

Labels

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