Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions docs/_scripts/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ def _slugify(text: str) -> str:
Returns:
The slugified text.
"""
# The type of the return value is not defined for the markdown library.
# Also for some reason `mypy` thinks the `toc` module doesn't have a
# `slugify_unicode` function, but it definitely does.
return toc.slugify_unicode(text, "-") # type: ignore[attr-defined,no-any-return]
return toc.slugify_unicode(text, "-")


def _hook_macros_plugin(env: macros.MacrosPlugin) -> None:
Expand Down
1 change: 0 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ plugins:
alias_type: redirect
canonical_version: latest
- mkdocstrings:
custom_templates: templates
default_handler: python
handlers:
python:
Expand Down
28 changes: 14 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,28 @@ dev-flake8 = [
"flake8 == 6.1.0",
"flake8-docstrings == 1.7.0",
"flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
"pydoclint == 0.3.3",
"pydoclint == 0.3.8",
"pydocstyle == 6.3.0",
]
dev-examples = ["polars == 0.19.3"]
dev-formatting = ["black == 23.9.1", "isort == 5.12.0"]
dev-examples = ["polars == 0.20.2"]
dev-formatting = ["black == 23.12.1", "isort == 5.13.2"]
dev-mkdocs = [
"black == 23.9.1",
"Markdown==3.4.4",
"black == 23.12.1",
"Markdown==3.5.1",
"mike == 2.0.0",
"mkdocs-gen-files == 0.5.0",
"mkdocs-literate-nav == 0.6.1",
"mkdocs-macros-plugin == 1.0.4",
"mkdocs-material == 9.3.1",
"mkdocstrings[python] == 0.23.0",
"mkdocs-macros-plugin == 1.0.5",
"mkdocs-material == 9.5.3",
"mkdocstrings[python] == 0.24.0",
"frequenz-repo-config[lib] == 0.7.4",
]
dev-mypy = [
"mypy == 1.5.1",
"mypy == 1.8.0",
"grpc-stubs == 1.24.12", # This dependency introduces breaking changes in patch releases
"types-Markdown == 3.4.2.10",
"types-Markdown == 3.5.0.3",
"types-PyYAML == 6.0.12.12",
"types-Pygments == 2.16.0.0",
"types-Pygments == 2.17.0.0",
"types-colorama == 0.4.15.12",
"types-protobuf == 4.24.0.4",
"types-python-dateutil == 2.8.19.14",
Expand All @@ -91,10 +91,10 @@ dev-pylint = [
"frequenz-sdk[dev-mkdocs,dev-noxfile,dev-pytest]",
]
dev-pytest = [
"pytest == 7.4.2",
"pytest == 7.4.4",
"frequenz-repo-config[extra-lint-examples] == 0.7.4",
"pytest-mock == 3.11.1",
"pytest-asyncio == 0.21.1",
"pytest-mock == 3.12.0",
"pytest-asyncio == 0.23.3",
"time-machine == 2.12.0",
"async-solipsism == 0.5",
# For checking docstring code examples
Expand Down
21 changes: 14 additions & 7 deletions src/frequenz/sdk/timeseries/_resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from collections.abc import AsyncIterator, Callable, Coroutine, Sequence
from dataclasses import dataclass
from datetime import datetime, timedelta, timezone
from typing import cast

from frequenz.channels.util import Timer
from frequenz.channels.util._timer import _to_microseconds
Expand Down Expand Up @@ -501,13 +502,19 @@ async def resample(self, *, one_shot: bool = False) -> None:
)

self._window_end += self._config.resampling_period
exceptions = {
source: results[i]
for i, source in enumerate(self._resamplers)
# CancelledError inherits from BaseException, but we don't want
# to catch *all* BaseExceptions here.
if isinstance(results[i], (Exception, asyncio.CancelledError))
}
# We need the cast because mypy is not able to infer that this can only
# contain Exception | CancelledError because of the condition in the list
# comprehension below.
exceptions = cast(
dict[Source, Exception | asyncio.CancelledError],
{
source: results[i]
for i, source in enumerate(self._resamplers)
# CancelledError inherits from BaseException, but we don't want
# to catch *all* BaseExceptions here.
if isinstance(results[i], (Exception, asyncio.CancelledError))
},
)
if exceptions:
raise ResamplingError(exceptions)
if one_shot:
Expand Down
30 changes: 16 additions & 14 deletions src/frequenz/sdk/timeseries/formula_engine/_formula_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,34 +54,36 @@
}
"""The dictionary of operator precedence for the shunting yard algorithm."""


# The `FormulaEngine*` and `HigherOrderFormulaBuilder*` classes are generic, but
# `TypeVar`s can't be defined on generic types, so we need to use `# type: ignore` to
# avoid mypy errors, and they get treated as `FormulaEngine[Any]`, etc.
#
# This is not ideal, but it's the best we can do until mypy supports generic types with
# `TypeVar`s.
_CompositionType = Union[
"FormulaEngine",
"HigherOrderFormulaBuilder",
"FormulaEngine3Phase",
"HigherOrderFormulaBuilder3Phase",
"FormulaEngine", # type: ignore[type-arg]
"HigherOrderFormulaBuilder", # type: ignore[type-arg]
"FormulaEngine3Phase", # type: ignore[type-arg]
"HigherOrderFormulaBuilder3Phase", # type: ignore[type-arg]
]

_CompositionType1Phase = Union[
"FormulaEngine",
"HigherOrderFormulaBuilder",
"FormulaEngine", # type: ignore[type-arg]
"HigherOrderFormulaBuilder", # type: ignore[type-arg]
]

_CompositionType3Phase = Union[
"FormulaEngine3Phase",
"HigherOrderFormulaBuilder3Phase",
"FormulaEngine3Phase", # type: ignore[type-arg]
"HigherOrderFormulaBuilder3Phase", # type: ignore[type-arg]
]

# The `FormulaEngine*` and `HigherOrderFormulaBuilder*` classes are generic, but
# `TypeVar`s can't be defined on generic types, so we need to use `# type: ignore` to
# avoid mypy errors, and they get treated as `FormulaEngine[Any]`, etc.
#
# This is not ideal, but it's the best we can do until mypy supports generic types with
# `TypeVar`s.
_GenericEngine = TypeVar(
"_GenericEngine",
"FormulaEngine", # type: ignore
"FormulaEngine3Phase", # type: ignore
)

_GenericHigherOrderBuilder = TypeVar(
"_GenericHigherOrderBuilder",
"HigherOrderFormulaBuilder", # type: ignore
Expand Down
8 changes: 4 additions & 4 deletions tests/microgrid/test_microgrid_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ def metadata(self) -> meta.Metadata:
@mock.patch("grpc.aio.insecure_channel")
async def test_connection_manager(
self,
_: MagicMock,
_insecure_channel_mock: MagicMock,
components: list[list[Component]],
connections: list[list[Connection]],
metadata: meta.Metadata,
) -> None:
"""Test microgrid api.

Args:
_: insecure channel mock from `mock.patch`
_insecure_channel_mock: insecure channel mock from `mock.patch`
components: components
connections: connections
metadata: the metadata of the microgrid
Expand Down Expand Up @@ -179,15 +179,15 @@ async def test_connection_manager(
@mock.patch("grpc.aio.insecure_channel")
async def test_connection_manager_another_method(
self,
_: MagicMock,
_insecure_channel_mock: MagicMock,
components: list[list[Component]],
connections: list[list[Connection]],
metadata: meta.Metadata,
) -> None:
"""Test if the api was not deallocated.

Args:
_: insecure channel mock
_insecure_channel_mock: insecure channel mock
components: components
connections: connections
metadata: the metadata of the microgrid
Expand Down