Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve type annotations #659

Merged
merged 12 commits into from
May 17, 2024
Merged

Conversation

njzjz
Copy link
Member

@njzjz njzjz commented May 17, 2024

I give up fix type annotations in all files, but it's meaningful to fix the top-module files dpdata/*.py.

Summary by CodeRabbit

  • New Features

    • Added name property to DPDataCalculator class.
    • Introduced assertion for rdkit_mol in bond order system.
  • Improvements

    • Enhanced type hinting across various functions and methods.
    • Added decorators and type assertion checks for better code validation.
  • Maintenance

    • Introduced a GitHub Actions workflow for running Pyright type checker.
    • Updated dependencies and configurations in pyproject.toml.

njzjz added 3 commits May 16, 2024 20:36
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Copy link

coderabbitai bot commented May 17, 2024

Walkthrough

The update introduces a GitHub Actions workflow for running the Pyright type checker, enhances type hinting across various modules, and makes significant changes to method signatures and class properties. These improvements aim to increase code reliability, maintainability, and type safety. Key updates include modifications to the DPDataCalculator class, bond_order_system, and extensive changes to method signatures in system.py.

Changes

Files Change Summaries
.github/workflows/pyright.yml Introduces a GitHub Actions workflow for running Pyright type checker.
dpdata/ase_calculator.py Updated DPDataCalculator class with a name property and modifications to calculate function.
dpdata/bond_order_system.py Added assertion for rdkit_mol and modified copy method.
dpdata/data_type.py Modified type hints in function signatures.
dpdata/driver.py Updated type hinting for get_driver and get_minimizer methods.
dpdata/format.py Added import and modified assignment in the decorator function.
dpdata/stat.py Added decorators and type assertion checks.
dpdata/system.py Extensive changes to method signatures and additions.
dpdata/utils.py Updated elements_index_map function with type hints and overloads.
pyproject.toml Added dependencies and configurations.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

njzjz added 3 commits May 16, 2024 20:42
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 16

Out of diff range and nitpick comments (2)
dpdata/ase_calculator.py (2)

Line range hint 54-75: Add type checks to avoid potential NoneType attribute errors.

-        assert atoms is not None
+        if atoms is None:
+            raise ValueError("`atoms` cannot be None")

Line range hint 1-1: Add the missing import for annotations.

+from __future__ import annotations

dpdata/driver.py Outdated Show resolved Hide resolved
dpdata/driver.py Outdated Show resolved Hide resolved
dpdata/bond_order_system.py Outdated Show resolved Hide resolved
dpdata/bond_order_system.py Show resolved Hide resolved
dpdata/format.py Outdated Show resolved Hide resolved
dpdata/system.py Outdated Show resolved Hide resolved
dpdata/system.py Outdated Show resolved Hide resolved
dpdata/system.py Show resolved Hide resolved
dpdata/system.py Show resolved Hide resolved
dpdata/system.py Show resolved Hide resolved
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Copy link

codspeed-hq bot commented May 17, 2024

CodSpeed Performance Report

Merging #659 will not alter performance

Comparing njzjz:improve-typing (24b93d5) with devel (a7bf93d)

Summary

✅ 2 untouched benchmarks

njzjz added 2 commits May 16, 2024 20:49
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Copy link

codecov bot commented May 17, 2024

Codecov Report

Attention: Patch coverage is 95.52846% with 11 lines in your changes are missing coverage. Please review.

Project coverage is 84.06%. Comparing base (a7bf93d) to head (24b93d5).

Files Patch % Lines
dpdata/bond_order_system.py 60.00% 2 Missing ⚠️
dpdata/system.py 98.09% 2 Missing ⚠️
dpdata/__about__.py 0.00% 1 Missing ⚠️
dpdata/__main__.py 0.00% 1 Missing ⚠️
dpdata/cli.py 0.00% 1 Missing ⚠️
dpdata/driver.py 87.50% 1 Missing ⚠️
dpdata/format.py 50.00% 1 Missing ⚠️
dpdata/md/rdf.py 0.00% 1 Missing ⚠️
dpdata/psi4/input.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            devel     #659      +/-   ##
==========================================
+ Coverage   83.86%   84.06%   +0.20%     
==========================================
  Files          81       81              
  Lines        6996     7122     +126     
==========================================
+ Hits         5867     5987     +120     
- Misses       1129     1135       +6     

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

njzjz added 2 commits May 16, 2024 21:06
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
@njzjz
Copy link
Member Author

njzjz commented May 17, 2024

@coderabbitai resolve

Copy link

coderabbitai bot commented May 17, 2024

Actions Performed

Comments resolved.

@njzjz njzjz marked this pull request as ready for review May 17, 2024 01:09
@njzjz njzjz requested a review from wanghan-iapcm May 17, 2024 01:09
@wanghan-iapcm wanghan-iapcm merged commit 626e692 into deepmodeling:devel May 17, 2024
12 checks passed
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.

None yet

2 participants