diff --git a/docs/_scripts/macros.py b/docs/_scripts/macros.py index 07ef28de3..0e0a6ff6c 100644 --- a/docs/_scripts/macros.py +++ b/docs/_scripts/macros.py @@ -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: diff --git a/mkdocs.yml b/mkdocs.yml index a83b7a137..79d4b4f27 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -96,7 +96,6 @@ plugins: alias_type: redirect canonical_version: latest - mkdocstrings: - custom_templates: templates default_handler: python handlers: python: diff --git a/pyproject.toml b/pyproject.toml index f959eaed6..a60a93bbd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", @@ -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 diff --git a/src/frequenz/sdk/timeseries/_resampling.py b/src/frequenz/sdk/timeseries/_resampling.py index 1dc1251ca..d60b15922 100644 --- a/src/frequenz/sdk/timeseries/_resampling.py +++ b/src/frequenz/sdk/timeseries/_resampling.py @@ -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 @@ -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: diff --git a/src/frequenz/sdk/timeseries/formula_engine/_formula_engine.py b/src/frequenz/sdk/timeseries/formula_engine/_formula_engine.py index b5cc63d2d..0c4159c7d 100644 --- a/src/frequenz/sdk/timeseries/formula_engine/_formula_engine.py +++ b/src/frequenz/sdk/timeseries/formula_engine/_formula_engine.py @@ -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 diff --git a/tests/microgrid/test_microgrid_api.py b/tests/microgrid/test_microgrid_api.py index c30ca387e..d74ae3f38 100644 --- a/tests/microgrid/test_microgrid_api.py +++ b/tests/microgrid/test_microgrid_api.py @@ -102,7 +102,7 @@ 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, @@ -110,7 +110,7 @@ async def test_connection_manager( """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 @@ -179,7 +179,7 @@ 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, @@ -187,7 +187,7 @@ async def test_connection_manager_another_method( """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