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

Mypy #217

Merged
merged 2 commits into from
Nov 26, 2024
Merged

Mypy #217

merged 2 commits into from
Nov 26, 2024

Conversation

Lasall
Copy link
Collaborator

@Lasall Lasall commented Nov 22, 2024

Add Mypy support:

  • Add to pre-commit (currently installs own deps, could maybe changed to poetry venv in the future to reuse environment and don't need duplicated types deps).
  • Add type hints (default mypy config).

In second commit:

  • Add missing annotations.
  • Enforce type hints.

Remarks:

  • Modules not supporting type hints (sklearn, deap, xprocess) and unused code (class_soc_calc.py) are ignored.
  • genetic.py: deap.creator.Individual is hinted as list[int] atm because it inherits from list and is filled with ints.
  • I was a little bit lazy with the numpy arrays and didn't explicitely write the types there.
  • Thanks to the type checking I found a few bugs and wrong hints.

Comment on lines +9 to 14
def max_ladeleistung_w_field(default: Optional[float] = None) -> Optional[float]:
return Field(
default,
default=default,
gt=0,
description="An integer representing the charging power of the battery in watts.",
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not familiar with pydantic, but shouldn't the return type hint be Field?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Field is actually a function but it returns a FieldInfo. The type annotation for the Field function however is Any as return type as it is assigned to the pydantic model field (with a user type like Optional[float]). Therefore this type hint cheats a bit in the way similar as it's done with the deap.creator.Individual -> list[int].

@NormannK
Copy link
Collaborator

id like to merge this next before it got hit by the very large PR #220
We be great if the conflicts can be resolved

 * Add to pre-commit (currently installs own deps, could maybe changed
   to poetry venv in the future to reuse environment and don't need
   duplicated types deps).
 * Add type hints.
@NormannK NormannK merged commit 6e52c9b into Akkudoktor-EOS:main Nov 26, 2024
2 checks passed
drbacke pushed a commit that referenced this pull request Jan 1, 2025
* Mypy: Initial support

 * Add to pre-commit (currently installs own deps, could maybe changed
   to poetry venv in the future to reuse environment and don't need
   duplicated types deps).
 * Add type hints.

* Mypy: Add missing annotations
Lasall added a commit that referenced this pull request Jan 1, 2025
* Mypy: Initial support

 * Add to pre-commit (currently installs own deps, could maybe changed
   to poetry venv in the future to reuse environment and don't need
   duplicated types deps).
 * Add type hints.

* Mypy: Add missing annotations
Lasall added a commit that referenced this pull request Jan 1, 2025
* Mypy: Initial support

 * Add to pre-commit (currently installs own deps, could maybe changed
   to poetry venv in the future to reuse environment and don't need
   duplicated types deps).
 * Add type hints.

* Mypy: Add missing annotations
@Lasall Lasall deleted the dl_dev-mypy branch January 1, 2025 13:42
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.

3 participants