Skip to content

♻️ Annotate types in aiida.common.datastructures.orbital (#7755) - #7756

Open
agarwalpranav0711 wants to merge 2 commits into
aiidateam:mainfrom
agarwalpranav0711:refactor/7755/orbital-type-annotations
Open

agarwalpranav0711 wants to merge 2 commits into
aiidateam:mainfrom
agarwalpranav0711:refactor/7755/orbital-type-annotations

Conversation

@agarwalpranav0711

Copy link
Copy Markdown

Description

Following PR #7672 (c990648f3), Orbital and RealhydrogenOrbital were relocated to src/aiida/common/datastructures/orbital.py. Because aiida.common.* is configured under strict type checking, this module was temporarily placed on the .pre-commit-config.yaml mypy exclude list.

This PR resolves #7755 by:

  • Adding complete type annotations to src/aiida/common/datastructures/orbital.py (Orbital, RealhydrogenOrbital, and all validator functions).
  • Fixing the variable reassignment in RealhydrogenOrbital.get_name_from_quantum_numbers where orbital_name was typed as list[str] and reassigned to str.
  • Properly typing _base_fields_required and _base_fields_optional specifications.
  • Removing src/aiida/common/datastructures/orbital.py from the mypy exclude list in .pre-commit-config.yaml.

Verification

  • uv run mypy src/aiida/common/ passes with 0 issues (resolving all 38 previous errors).
  • uv run pytest tests/tools/data/orbital/test_orbitals.py passes all 8 tests.
  • uv run ruff check . and uv run ruff format --check pass cleanly.

Fixes #7755

)

Add full type annotations to Orbital and RealhydrogenOrbital, resolve
all 38 mypy errors in the module, and remove the file from the mypy
exclude list in .pre-commit-config.yaml.
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between b1662d0 and f6f93b3.

Files selected for processing: 1
  • src/aiida/common/datastructures/orbital.py

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Walkthrough

The orbital module gains type annotations, and the local mypy hook now checks it. RealhydrogenOrbital.__str__ also omits an extra space before @ when no kind name is set.

Changes: Orbital typing and mypy coverage

Layer / File(s) Summary
Type validators and Orbital fields
src/aiida/common/datastructures/orbital.py
Validator functions and Orbital fields and methods gain type annotations. The validation and initialization logic remains unchanged.
RealhydrogenOrbital and mypy coverage
src/aiida/common/datastructures/orbital.py, .pre-commit-config.yaml
RealhydrogenOrbital fields and methods gain type annotations. Its string representation omits the space before @ when no kind name is set. The mypy exclusion for the module is removed.

Priority: Low

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Refactor

Merge Risk: Minimal · up to f6f93

No actionable merge-blocking risk is identified in the reviewed changes.

Pre-merge checks: Passed 5
Check name Status Explanation
Description check Passed The description clearly explains the type annotation changes, the mypy exclusion removal, the typing fix, and the reported verification results.
Title check Passed The title clearly and concisely identifies the main change: adding type annotations in aiida.common.datastructures.orbital.
Linked Issues check Passed Issue #7755 requirements are implemented. The diff adds annotations to the validators, Orbital, RealhydrogenOrbital, CONVERSION_DICT, and the field specifications. It separates `matching_orbital…
Out of Scope Changes check Passed The reviewed changes stay within issue #7755. The RealhydrogenOrbital.__str__ change is limited to the required return annotation, and the current body preserves the original formatting and key acce…
Docstring Coverage Passed Docstring coverage is 80.95% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 1 files.
Full details: Linked Issues check

Explanation

Issue #7755 requirements are implemented. The diff adds annotations to the validators, Orbital, RealhydrogenOrbital, CONVERSION_DICT, and the field specifications. It separates matching_orbitals, family_name, and sub_orbitals in get_name_from_quantum_numbers, so orbital_name is not reassigned between list and string types. The diff removes the orbital module from the mypy exclusion list, as also stated in the PR evidence. The PR reports that mypy src/aiida/common/ passes with 0 issues and that all 8 orbital tests pass.

Full details: Out of Scope Changes check

Explanation

The reviewed changes stay within issue #7755. The RealhydrogenOrbital.__str__ change is limited to the required return annotation, and the current body preserves the original formatting and key access. The remaining changes add typing or rename local variables to support typing.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@agarwalpranav0711

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@agarwalpranav0711
agarwalpranav0711 marked this pull request as ready for review October 23, 2026 17:08
@agarwalpranav0711

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

This branch has not been deployed

No deployments
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.

Add type annotations to aiida.common.datastructures.orbital and enable mypy

1 participant