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

Complete type annotations #399

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

FabianHofmann
Copy link
Collaborator

No description provided.

@FabianHofmann FabianHofmann requested a review from lkstrp December 30, 2024 21:54
Copy link
Member

@lkstrp lkstrp left a comment

Choose a reason for hiding this comment

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

Tons of types 💃

Why did you remove py.typed? It is currently broken, but the whole goal of this operaiton should be to make linopy a typed package. Otherwise it is only useful for internal development.

@@ -26,3 +26,4 @@ benchmark/notebooks/.ipynb_checkpoints
benchmark/scripts/__pycache__
benchmark/scripts/benchmarks-pypsa-eur/__pycache__
benchmark/scripts/leftovers/
.aider*
Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines +484 to +505
@overload
def iterate_slices(
ds: Dataset,
slice_size: int | None = 10_000,
slice_dims: list | None = None,
) -> Generator[Dataset, None, None]: ...


@overload
def iterate_slices(
ds: Variable,
slice_size: int | None = 10_000,
slice_dims: list | None = None,
) -> Generator[Variable, None, None]: ...


@overload
def iterate_slices(
ds: LinearExpression,
slice_size: int | None = 10_000,
slice_dims: list | None = None,
) -> Generator[LinearExpression, None, None]: ...
Copy link
Member

Choose a reason for hiding this comment

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

🚀
Were you just playing around, or do you think we could use overloading a lot more everywhere?
I wasn't sure. Probably great for type checking and IDE hints, but also adds a bit of boilerplate. We'll probably want to do stub files at some point.

@@ -11,7 +11,7 @@
import numpy as np
import pandas as pd

logger = logging.getLogger(__name__)
logger: logging.Logger = logging.getLogger(__name__)
Copy link
Member

Choose a reason for hiding this comment

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

What was the mypy issue here? Type Any because logging is not typed? But you did not set that rule

@@ -685,7 +688,7 @@ class Constraints:
"""

data: dict[str, Constraint]
model: "Model" # Model is not defined due to circular imports
model: Model # Model is not defined due to circular imports
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
model: Model # Model is not defined due to circular imports
model: Model

| Mapping
| DataArrayCoordinates
| DatasetCoordinates
| None
Copy link
Member

Choose a reason for hiding this comment

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

Isn't CoordsLike still a more consistent name, even if there is no Coords class? Otherwise, when reading the types, my first assumption is that this is a class and not a type alias.

Also, should None also go in there?

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.

2 participants