From 886796814d61eae6114f79f781d2591b9a73129c Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 14 May 2025 13:59:24 -0500 Subject: [PATCH] Annotate product, reverse_dictionary --- .basedpyright/baseline.json | 64 ------------------------------------- pytools/__init__.py | 8 +++-- 2 files changed, 5 insertions(+), 67 deletions(-) diff --git a/.basedpyright/baseline.json b/.basedpyright/baseline.json index 16b09c48..8819d971 100644 --- a/.basedpyright/baseline.json +++ b/.basedpyright/baseline.json @@ -3291,14 +3291,6 @@ "lineCount": 1 } }, - { - "code": "reportAny", - "range": { - "startColumn": 4, - "endColumn": 11, - "lineCount": 1 - } - }, { "code": "reportAny", "range": { @@ -3307,62 +3299,6 @@ "lineCount": 1 } }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 4, - "endColumn": 22, - "lineCount": 1 - } - }, - { - "code": "reportUnknownParameterType", - "range": { - "startColumn": 23, - "endColumn": 31, - "lineCount": 1 - } - }, - { - "code": "reportMissingParameterType", - "range": { - "startColumn": 23, - "endColumn": 31, - "lineCount": 1 - } - }, - { - "code": "reportUnknownVariableType", - "range": { - "startColumn": 8, - "endColumn": 11, - "lineCount": 1 - } - }, - { - "code": "reportUnknownVariableType", - "range": { - "startColumn": 13, - "endColumn": 18, - "lineCount": 1 - } - }, - { - "code": "reportUnknownMemberType", - "range": { - "startColumn": 22, - "endColumn": 36, - "lineCount": 1 - } - }, - { - "code": "reportUnknownVariableType", - "range": { - "startColumn": 11, - "endColumn": 17, - "lineCount": 1 - } - }, { "code": "reportAny", "range": { diff --git a/pytools/__init__.py b/pytools/__init__.py index 44c7ad6e..1f69e716 100644 --- a/pytools/__init__.py +++ b/pytools/__init__.py @@ -253,6 +253,8 @@ R = TypeVar("R") F = TypeVar("F", bound=Callable[..., Any]) P = ParamSpec("P") +K = TypeVar("K") +V = TypeVar("V") # }}} @@ -1120,13 +1122,13 @@ def partition2(iterable): return part_true, part_false -def product(iterable: Iterable[Any]) -> Any: +def product(iterable: Iterable[T]) -> T | int: from operator import mul return reduce(mul, iterable, 1) -def reverse_dictionary(the_dict): - result = {} +def reverse_dictionary(the_dict: Mapping[K, V]) -> dict[V, K]: + result: dict[V, K] = {} for key, value in the_dict.items(): if value in result: raise RuntimeError(