Skip to content

Enable ruff rule ANN and fix errors#568

Draft
Copilot wants to merge 52 commits intomasterfrom
copilot/enable-ruff-rule-ann
Draft

Enable ruff rule ANN and fix errors#568
Copilot wants to merge 52 commits intomasterfrom
copilot/enable-ruff-rule-ann

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 16, 2026

Enable ruff rule ANN

  • Enable ANN rule in pyproject.toml configuration
  • Apply auto-fixes file by file
  • Add type annotations to remaining files
  • Remove ANN ignores
  • Run tests to ensure changes don't break functionality
  • Replace Any with proper class types (Job, Submission, Context, Machine, Resources)
  • Fix Python version compatibility (Union syntax)

Summary

This PR enables the ruff ANN (flake8-annotations) rule and adds comprehensive type annotations throughout the dpdispatcher codebase.

Changes Made

  • Configuration: Enabled ANN rule in pyproject.toml without any ignores
  • Type Annotations: Added type annotations to 730+ locations across 36 files:
    • Function parameters (ANN001, ANN002, ANN003)
    • Return types (ANN201, ANN202, ANN204, ANN205, ANN206)
    • Core modules: submission.py, machine.py, base_context.py
    • Context modules: All 6 context implementations
    • Machine modules: All 9 scheduler implementations
    • Utility modules: client.py, utils.py, hdfs_cli.py, and others
    • Test files: Multiple test modules
  • Imports: Added necessary typing imports (Any, Dict, List, Optional, Tuple, Union, TYPE_CHECKING)
  • Type Refinement: Replaced Any with proper class types (Submission, Job, Task, Machine, Resources, BaseContext)
  • Python Compatibility: Fixed union syntax to use Union[int, JobStatus] instead of int | JobStatus for Python 3.7+ support
  • Methodology: Fixed and committed each file individually (52 commits total)

Testing

  • ✅ Zero ANN violations (ruff check --select ANN passes)
  • ✅ All 153 tests pass (42 skipped for environment reasons)
  • ✅ Pre-commit hooks pass
  • ✅ No breaking changes to functionality
  • ✅ Compatible with Python 3.7+

The codebase now has comprehensive type annotations with proper domain types, improving code quality, IDE support, and type safety.

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)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@njzjz
Copy link
Copy Markdown
Member

njzjz commented Feb 16, 2026

Commit after each file is modified.@copilot

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

njzjz commented Feb 16, 2026

@copilot Commit a file after this is modified. Do not ignore errors.

@njzjz
Copy link
Copy Markdown
Member

njzjz commented Feb 17, 2026

@copilot Commit each file after this file is modified. Do not ignore ruff lint errors.

retry

Copilot AI and others added 16 commits February 17, 2026 23:04
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI and others added 4 commits February 17, 2026 23:36
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 17, 2026

@copilot Commit each file after this file is modified. Do not ignore ruff lint errors.

retry

Completed. All ANN violations fixed across 36 files with individual commits (862dfae through 9179f89). Zero ANN errors remaining, all tests pass.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 39.106.xx.xx
    • Triggering command: /home/REDACTED/work/dpdispatcher/dpdispatcher/.venv/bin/python python -m coverage run -p --source=./dpdispatcher -m unittest -v uname sh nv-python3/bin/python --no�� --noprofile rsion_info)) (dns block)
    • Triggering command: /home/REDACTED/work/dpdispatcher/dpdispatcher/.venv/bin/python python -m unittest discover -s tests -p test_*.py -v -d 168.63.129.16 /usr/lib/git-core/git d2ba�� --no-ext-diff --no-textconv /usr/local/sbin/bash 0 -j ACCEPT bash (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Enable ruff rule ANN and fix errors Enable ruff rule ANN and fix errors Feb 17, 2026
Copilot AI requested a review from njzjz February 17, 2026 23:49
@njzjz
Copy link
Copy Markdown
Member

njzjz commented Feb 18, 2026

@copilot please note that some classes like Job, Submission, Context, etc should be used instead of Any.

Copilot AI and others added 13 commits February 18, 2026 01:05
- Replace submission: Any with submission: Submission
- Add TYPE_CHECKING import to avoid circular imports
- Use forward reference for Submission type

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Replace job: Any with job: Job
- Replace submission: Any with submission: Submission
- Replace res/resources: Any with Resources
- Add TYPE_CHECKING imports for Job, Resources, Submission
- Import JobStatus for check_status return type

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Replace context: Any with context: BaseContext in Task.get_task_state
- Add TYPE_CHECKING import for BaseContext

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…t.py

- Replace submission: Any with submission: Submission
- Add TYPE_CHECKING import for Submission

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Replace submission: Any with submission: Submission
- Add TYPE_CHECKING import for Submission

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Replace submission: Any with submission: Submission
- Add TYPE_CHECKING import for Submission

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Replace submission: Any with submission: Submission
- Add TYPE_CHECKING import for Submission

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ontext.py

- Replace submission: Any with submission: Submission
- Replace job: Any with job: Job
- Add TYPE_CHECKING imports for Job, Submission

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Replace res: Any with res: Resources
- Add Resources to TYPE_CHECKING imports
- Fix return types for sub_script_cmd and sub_script_head

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Replace group_id: Any with group_id: Optional[int]
- Replace status: Any with status: int | JobStatus
- Return type for _get_job_detail is Dict[str, Any]

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Replace group_id: Any with group_id: Optional[int]
- Replace status: Any with status: int | JobStatus
- Return type for _get_job_detail is Dict[str, Any]

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 18, 2026

@copilot please note that some classes like Job, Submission, Context, etc should be used instead of Any.

Replaced Any with proper types across 13 files (8c43572 through 6e8a844):

  • submission: Anysubmission: "Submission"
  • job: Anyjob: "Job"
  • task: Anytask: "Task"
  • context: Anycontext: "BaseContext"
  • machine: Anymachine: "Machine"
  • resources: Anyresources: "Resources"

Used TYPE_CHECKING imports to avoid circular dependencies. Kept Any only for *args, **kwargs, and Dict[str, Any] return values.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 39.106.xx.xx
    • Triggering command: /home/REDACTED/work/dpdispatcher/dpdispatcher/.venv/bin/python python -m coverage run -p --source=./dpdispatcher -m unittest -v (dns block)
    • Triggering command: /home/REDACTED/work/dpdispatcher/dpdispatcher/.venv/bin/python python -m coverage run -p --source=./dpdispatcher -m unittest (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@njzjz
Copy link
Copy Markdown
Member

njzjz commented Feb 23, 2026

@copilot TypeError: unsupported operand type(s) for |: 'type' and 'EnumMeta'

Replace `int | JobStatus` with `Union[int, JobStatus]` to support Python 3.7+.
The `|` union operator syntax was introduced in Python 3.10, but the project
requires Python >=3.7.

Fixes TypeError: unsupported operand type(s) for |: 'type' and 'EnumMeta'

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

Copilot AI commented Feb 23, 2026

@copilot TypeError: unsupported operand type(s) for |: 'type' and 'EnumMeta'

Fixed in commit 2604cb3. Replaced int | JobStatus with Union[int, JobStatus] in dp_cloud_server.py and openapi.py. The | union operator requires Python 3.10+, but the project supports Python 3.7+.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 39.106.xx.xx
    • Triggering command: /home/REDACTED/work/dpdispatcher/dpdispatcher/.venv/bin/python python -m unittest discover -s tests -p test_*.py -v (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

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