Skip to content

style: enable ruff ANN rule for type annotations#98

Merged
njzjz merged 5 commits intomasterfrom
copilot/enable-ruff-rule-ann
Feb 17, 2026
Merged

style: enable ruff ANN rule for type annotations#98
njzjz merged 5 commits intomasterfrom
copilot/enable-ruff-rule-ann

Conversation

Copy link
Contributor

Copilot AI commented Feb 17, 2026

Enable ruff rule ANN

Plan to enable the ANN (type annotations) rule in ruff configuration and fix all violations:

  • Understand the issue and explore the repository
  • Update pyproject.toml to enable ANN rule in ruff configuration
  • Apply ruff auto-fixes with --unsafe-fixes to automatically add type annotations
  • Manually review and fix remaining ANN violations in dargs package:
    • Fixed all function argument type annotations
    • Fixed all return type annotations
    • Configured ANN401 to be ignored (necessary for library handling arbitrary types)
    • Configured allow-star-arg-any for *args/**kwargs
  • Fix remaining ANN violations in tests directory
  • Run tests to ensure changes don't break functionality (34 passed, 1 skipped)
  • Run final ruff check to verify all ANN violations are resolved (0 errors)
  • Request code review (no issues found)
  • Fix basedpyright type errors:
    • Fixed _DUMMYHOOK type signature to accept both Argument and Variant
    • Fixed gen_doc_head to handle None path when make_anchor is True
    • Fixed _get_type_name to handle None value properly

Summary

Successfully enabled the ANN (flake8-annotations) rule in ruff configuration. Added type annotations to 170+ functions and parameters across the codebase. All tests pass and ruff checks pass with zero errors. Fixed basedpyright type checking errors.

Original prompt

This section details on the original issue you should resolve

<issue_title>Enable ruff rule ANN</issue_title>
<issue_description>Enable ruff rule ANN. Fix errors.

Follow https://github.com/astral-sh/claude-code-plugins/blob/main/plugins/astral/skills/ruff/SKILL.md</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 17, 2026 06:52
Co-authored-by: njzjz <9496702+njzjz@users.noreply.github.com>
Co-authored-by: njzjz <9496702+njzjz@users.noreply.github.com>
Copilot AI changed the title [WIP] Enable ruff rule ANN and fix errors Enable ruff ANN rule for type annotations Feb 17, 2026
Copilot AI requested a review from njzjz February 17, 2026 06:57
@njzjz njzjz marked this pull request as ready for review February 17, 2026 13:26
Copilot AI review requested due to automatic review settings February 17, 2026 13:26
@njzjz njzjz closed this Feb 17, 2026
@njzjz njzjz reopened this Feb 17, 2026
@codecov
Copy link

codecov bot commented Feb 17, 2026

Codecov Report

❌ Patch coverage is 84.31373% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.32%. Comparing base (dc26890) to head (f4dba3d).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
dargs/sphinx.py 0.00% 5 Missing ⚠️
dargs/cli.py 0.00% 2 Missing ⚠️
dargs/dargs.py 97.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #98      +/-   ##
==========================================
- Coverage   74.34%   74.32%   -0.03%     
==========================================
  Files           9        9              
  Lines         807      810       +3     
==========================================
+ Hits          600      602       +2     
- Misses        207      208       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@njzjz
Copy link
Member

njzjz commented Feb 17, 2026

@copilot Run pipx run uv tool run --with .[typecheck] basedpyright
creating virtual environment...
installing uv...
Building dargs @ file:///home/runner/work/dargs/dargs
Downloading babel (9.7MiB)
Downloading sphinx (3.7MiB)
Downloading jedi (1.5MiB)
Downloading pygments (1.2MiB)
Downloading nodejs-wheel-binaries (57.0MiB)
Downloading basedpyright (9.9MiB)
Built dargs @ file:///home/runner/work/dargs/dargs
Downloaded pygments
Downloaded sphinx
Downloaded babel
Downloaded jedi
Downloaded basedpyright
Downloaded nodejs-wheel-binaries
Installed 42 packages in 105ms
/home/runner/work/dargs/dargs/dargs/dargs.py:336:38 - error: Expression of type "(a: Argument, x: dict[Unknown, Unknown] | Any, p: list[str]) -> None" cannot be assigned to parameter of type "HookVrntType"
Type "(a: Argument, x: dict[Unknown, Unknown] | Any, p: list[str]) -> None" is incompatible with type "HookVrntType"
Parameter 1: type "Variant" is incompatible with type "Argument"
"Variant" is incompatible with "Argument" (reportArgumentType)
Error: Expression of type "(a: Argument, x: dict[Unknown, Unknown] | Any, p: list[str]) -> None" cannot be assigned to parameter of type "HookVrntType"
Type "(a: Argument, x: dict[Unknown, Unknown] | Any, p: list[str]) -> None" is incompatible with type "HookVrntType"
Parameter 1: type "Variant" is incompatible with type "Argument"
"Variant" is incompatible with "Argument" (reportArgumentType)
/home/runner/work/dargs/dargs/dargs/dargs.py:359:38 - error: Expression of type "(a: Argument, x: dict[Unknown, Unknown] | Any, p: list[str]) -> None" cannot be assigned to parameter of type "HookVrntType"
Type "(a: Argument, x: dict[Unknown, Unknown] | Any, p: list[str]) -> None" is incompatible with type "HookVrntType"
Parameter 1: type "Variant" is incompatible with type "Argument"
"Variant" is incompatible with "Argument" (reportArgumentType)
Error: Expression of type "(a: Argument, x: dict[Unknown, Unknown] | Any, p: list[str]) -> None" cannot be assigned to parameter of type "HookVrntType"
Type "(a: Argument, x: dict[Unknown, Unknown] | Any, p: list[str]) -> None" is incompatible with type "HookVrntType"
Parameter 1: type "Variant" is incompatible with type "Argument"
"Variant" is incompatible with "Argument" (reportArgumentType)
/home/runner/work/dargs/dargs/dargs/dargs.py:397:38 - error: Expression of type "(a: Argument, x: dict[Unknown, Unknown] | Any, p: list[str]) -> None" cannot be assigned to parameter of type "HookVrntType"
Type "(a: Argument, x: dict[Unknown, Unknown] | Any, p: list[str]) -> None" is incompatible with type "HookVrntType"
Parameter 1: type "Variant" is incompatible with type "Argument"
"Variant" is incompatible with "Argument" (reportArgumentType)
Error: Expression of type "(a: Argument, x: dict[Unknown, Unknown] | Any, p: list[str]) -> None" cannot be assigned to parameter of type "HookVrntType"
Type "(a: Argument, x: dict[Unknown, Unknown] | Any, p: list[str]) -> None" is incompatible with type "HookVrntType"
Parameter 1: type "Variant" is incompatible with type "Argument"
"Variant" is incompatible with "Argument" (reportArgumentType)
/home/runner/work/dargs/dargs/dargs/dargs.py:672:38 - error: Argument of type "list[str] | None" cannot be assigned to parameter "name" of type "str | list[str]" in function "make_rst_refid" (reportArgumentType)
Error: Argument of type "list[str] | None" cannot be assigned to parameter "name" of type "str | list[str]" in function "make_rst_refid" (reportArgumentType)
/home/runner/work/dargs/dargs/dargs/dargs.py:718:68 - error: "name" is not a known attribute of "None" (reportOptionalMemberAccess)
Error: "name" is not a known attribute of "None" (reportOptionalMemberAccess)
Error: 5 errors
5 errors, 0 warnings, 0 notes
Error: Process completed with exit code 1.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enables the flake8-annotations (ANN) rule in ruff to enforce type annotations across the entire dargs codebase. The changes add return type and parameter type annotations to approximately 170 functions while preserving legitimate uses of Any for the library's dynamic type handling needs.

Changes:

  • Enabled ANN rule in ruff configuration with ANN401 (any-type) exception and allow-star-arg-any setting
  • Added comprehensive type annotations to core library modules (dargs.py, cli.py, sphinx.py, notebook.py)
  • Added type annotations to all test methods and test helper functions

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pyproject.toml Added ANN to ruff select list, ignored ANN401 for Any usage, enabled allow-star-arg-any configuration
dargs/dargs.py Added return types and parameter types to ~60 methods including Argument/Variant classes and utility functions
dargs/cli.py Added type annotations to CLI entry points and command functions
dargs/sphinx.py Added type annotations to Sphinx directive and domain classes
dargs/notebook.py Added type annotations to Jupyter notebook display functions and ArgumentData class
docs/conf.py Added type annotations to Sphinx setup and apidoc functions
tests/dpmdargs.py Added type annotations to ~40 test helper functions that generate argument structures
tests/test_checker.py Added -> None return type to all test methods
tests/test_cli.py Added -> None return type to all test methods
tests/test_creation.py Added -> None return type to all test methods
tests/test_docgen.py Added -> None return type to all test methods
tests/test_json_schema.py Added -> None return type to all test methods
tests/test_normalizer.py Added -> None return type to all test methods and helper function
tests/test_notebook.py Added -> None return type to test method

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Fix _DUMMYHOOK to accept Argument | Variant for first parameter
- Fix gen_doc_head to handle None path when make_anchor is True
- Fix _get_type_name to handle None value properly

Co-authored-by: njzjz <9496702+njzjz@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 17, 2026

@copilot Run pipx run uv tool run --with .[typecheck] basedpyright
creating virtual environment...
installing uv...
...

Fixed the basedpyright type errors in commit f4dba3d:

  1. Changed _DUMMYHOOK signature to accept Argument | Variant as first parameter (fixes errors at lines 336, 359, 397)
  2. Added null check in gen_doc_head to handle None path when make_anchor is True (fixes error at line 672)
  3. Added None check in _get_type_name to handle None value (fixes error at line 718)

All tests pass (34 passed, 1 skipped).

@njzjz njzjz changed the title Enable ruff ANN rule for type annotations style: enable ruff ANN rule for type annotations Feb 17, 2026
@njzjz njzjz merged commit b573292 into master Feb 17, 2026
14 checks passed
@njzjz njzjz deleted the copilot/enable-ruff-rule-ann branch February 17, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable ruff rule ANN

2 participants

Comments