From 0e80aa60a7f4f345c571e020c0338c9f86223f26 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Sat, 11 Nov 2023 15:43:37 -0600 Subject: [PATCH] Delete type-ignores that mypy 1.7 says are unneeded --- pytato/analysis/__init__.py | 12 +++---- pytato/codegen.py | 6 ++-- pytato/distributed/partition.py | 6 ++-- pytato/distributed/verify.py | 6 ++-- pytato/pad.py | 15 ++------- pytato/scalar_expr.py | 2 +- pytato/stringifier.py | 16 +++------ pytato/transform/__init__.py | 36 +++++++-------------- pytato/transform/einsum_distributive_law.py | 6 ++-- pytato/transform/lower_to_index_lambda.py | 2 +- pytato/transform/metadata.py | 6 ++-- pytato/visualization/dot.py | 3 +- 12 files changed, 36 insertions(+), 80 deletions(-) diff --git a/pytato/analysis/__init__.py b/pytato/analysis/__init__.py index d0fd6ef..e49fc7d 100644 --- a/pytato/analysis/__init__.py +++ b/pytato/analysis/__init__.py @@ -377,12 +377,10 @@ class NodeCountMapper(CachedWalkMapper): super().__init__() self.count = 0 - # type-ignore-reason: dropped the extra `*args, **kwargs`. - def get_cache_key(self, expr: ArrayOrNames) -> int: # type: ignore[override] + def get_cache_key(self, expr: ArrayOrNames) -> int: return id(expr) - # type-ignore-reason: dropped the extra `*args, **kwargs`. - def post_visit(self, expr: Any) -> None: # type: ignore[override] + def post_visit(self, expr: Any) -> None: self.count += 1 @@ -416,8 +414,7 @@ class CallSiteCountMapper(CachedWalkMapper): super().__init__() self.count = 0 - # type-ignore-reason: dropped the extra `*args, **kwargs`. - def get_cache_key(self, expr: ArrayOrNames) -> int: # type: ignore[override] + def get_cache_key(self, expr: ArrayOrNames) -> int: return id(expr) @memoize_method @@ -434,8 +431,7 @@ class CallSiteCountMapper(CachedWalkMapper): self.post_visit(expr, *args, **kwargs) - # type-ignore-reason: dropped the extra `*args, **kwargs`. - def post_visit(self, expr: Any) -> None: # type: ignore[override] + def post_visit(self, expr: Any) -> None: if isinstance(expr, Call): self.count += 1 diff --git a/pytato/codegen.py b/pytato/codegen.py index 68f4645..ab67db4 100644 --- a/pytato/codegen.py +++ b/pytato/codegen.py @@ -230,12 +230,10 @@ class NamesValidityChecker(CachedWalkMapper): self.name_to_input: Dict[str, InputArgumentBase] = {} super().__init__() - # type-ignore-reason: dropped the extra `*args, **kwargs`. - def get_cache_key(self, expr: ArrayOrNames) -> int: # type: ignore[override] + def get_cache_key(self, expr: ArrayOrNames) -> int: return id(expr) - # type-ignore-reason: dropped the extra `*args, **kwargs`. - def post_visit(self, expr: Any) -> None: # type: ignore[override] + def post_visit(self, expr: Any) -> None: if isinstance(expr, (Placeholder, SizeParam, DataWrapper)): if expr.name is not None: try: diff --git a/pytato/distributed/partition.py b/pytato/distributed/partition.py index 433fda1..dc6a051 100644 --- a/pytato/distributed/partition.py +++ b/pytato/distributed/partition.py @@ -608,12 +608,10 @@ class _MaterializedArrayCollector(CachedWalkMapper): super().__init__() self.materialized_arrays: _OrderedSet[Array] = _OrderedSet() - # type-ignore-reason: dropped the extra `*args, **kwargs`. - def get_cache_key(self, expr: ArrayOrNames) -> int: # type: ignore[override] + def get_cache_key(self, expr: ArrayOrNames) -> int: return id(expr) - # type-ignore-reason: dropped the extra `*args, **kwargs`. - def post_visit(self, expr: Any) -> None: # type: ignore[override] + def post_visit(self, expr: Any) -> None: from pytato.tags import ImplStored from pytato.loopy import LoopyCallResult diff --git a/pytato/distributed/verify.py b/pytato/distributed/verify.py index c324b67..00535ad 100644 --- a/pytato/distributed/verify.py +++ b/pytato/distributed/verify.py @@ -138,12 +138,10 @@ class _SeenNodesWalkMapper(CachedWalkMapper): super().__init__() self.seen_nodes: Set[ArrayOrNames] = set() - # type-ignore-reason: dropped the extra `*args, **kwargs`. - def get_cache_key(self, expr: ArrayOrNames) -> int: # type: ignore[override] + def get_cache_key(self, expr: ArrayOrNames) -> int: return id(expr) - # type-ignore-reason: dropped the extra `*args, **kwargs`. - def visit(self, expr: ArrayOrNames) -> bool: # type: ignore[override] + def visit(self, expr: ArrayOrNames) -> bool: super().visit(expr) self.seen_nodes.add(expr) return True diff --git a/pytato/pad.py b/pytato/pad.py index 6576530..6c166ce 100644 --- a/pytato/pad.py +++ b/pytato/pad.py @@ -86,10 +86,7 @@ def _normalize_pad_width( and isinstance(pad_width[0], INT_CLASSES) and isinstance(pad_width[1], INT_CLASSES) ): - # type-ignore-reason: mypy does not take the guarding predicate into - # account - processed_pad_widths = [pad_width # type: ignore[misc] - for _ in range(array.ndim)] + processed_pad_widths = [pad_width for _ in range(array.ndim)] elif isinstance(pad_width, abc.Sequence): if len(pad_width) != array.ndim: raise ValueError(f"Number of pad widths != {array.ndim}" @@ -191,10 +188,7 @@ def pad(array: Array, and np.isscalar(constant_vals[0]) and np.isscalar(constant_vals[1]) ): - # type-ignore-reason: mypy does not understand the guarding - # predicate - processed_constant_vals = [constant_vals # type: ignore[misc] - for _ in range(array.ndim)] + processed_constant_vals = [constant_vals for _ in range(array.ndim)] elif isinstance(constant_vals, abc.Sequence): if len(constant_vals) != array.ndim: raise ValueError("") @@ -205,10 +199,7 @@ def pad(array: Array, and len(constant_val) == 2 and np.isscalar(constant_val[0]) and np.isscalar(constant_val[1])): - # type-ignore-reason: mypy does not understand the guarding - # predicate - processed_constant_vals.append( - constant_val) # type: ignore[arg-type] + processed_constant_vals.append(constant_val) else: raise ValueError( "Elements of `constant_vals` must be of type" diff --git a/pytato/scalar_expr.py b/pytato/scalar_expr.py index 0e21c28..a0930f4 100644 --- a/pytato/scalar_expr.py +++ b/pytato/scalar_expr.py @@ -286,7 +286,7 @@ class InductionVariableCollector(CombineMapper): from functools import reduce return reduce(frozenset.union, values, frozenset()) - def map_reduce(self, expr: Reduce) -> FrozenSet[str]: # type: ignore[override] + def map_reduce(self, expr: Reduce) -> FrozenSet[str]: return self.combine([frozenset(expr.bounds.keys()), super().map_reduce(expr)]) diff --git a/pytato/stringifier.py b/pytato/stringifier.py index 269c9a5..a881572 100644 --- a/pytato/stringifier.py +++ b/pytato/stringifier.py @@ -59,8 +59,7 @@ class Reprifier(Mapper): self._cache: Dict[Tuple[int, int], str] = {} - # type-ignore-reason: incompatible with super class - def rec(self, expr: Any, depth: int) -> str: # type: ignore[override] + def rec(self, expr: Any, depth: int) -> str: cache_key = (id(expr), depth) try: return self._cache[cache_key] @@ -69,12 +68,10 @@ class Reprifier(Mapper): self._cache[cache_key] = result return result # type: ignore[no-any-return] - # type-ignore-reason: incompatible with super class - def __call__(self, expr: Any, depth: int = 0) -> str: # type: ignore[override] + def __call__(self, expr: Any, depth: int = 0) -> str: return self.rec(expr, depth) - # type-ignore-reason: incompatible with super class - def map_foreign(self, expr: Any, depth: int) -> str: # type: ignore[override] + def map_foreign(self, expr: Any, depth: int) -> str: if isinstance(expr, tuple): return "(" + ", ".join(self.rec(el, depth) for el in expr) + ")" elif isinstance(expr, (dict, immutabledict)): @@ -95,9 +92,7 @@ class Reprifier(Mapper): if depth > self.truncation_depth: return self.truncation_string - # type-ignore-reason: https://github.com/python/mypy/issues/16254 - fields = tuple(field.name - for field in attrs.fields(type(expr))) # type: ignore[misc] + fields = tuple(field.name for field in attrs.fields(type(expr))) if expr.ndim <= 1: # prettify: if ndim <=1 'expr.axes' would be trivial, @@ -155,8 +150,7 @@ class Reprifier(Mapper): return (f"{type(expr).__name__}(" + ", ".join(f"{field.name}={_get_field_val(field.name)}" - # type-ignore-reason: https://github.com/python/mypy/issues/16254 - for field in attrs.fields(type(expr))) # type: ignore[misc] + for field in attrs.fields(type(expr))) + ")") def map_loopy_call(self, expr: LoopyCall, depth: int) -> str: diff --git a/pytato/transform/__init__.py b/pytato/transform/__init__.py index 69cfd1e..737fbce 100644 --- a/pytato/transform/__init__.py +++ b/pytato/transform/__init__.py @@ -206,8 +206,7 @@ class CachedMapper(Mapper, Generic[CachedMapperT]): def get_cache_key(self, expr: ArrayOrNames) -> Hashable: return expr - # type-ignore-reason: incompatible with super class - def rec(self, expr: ArrayOrNames) -> CachedMapperT: # type: ignore[override] + def rec(self, expr: ArrayOrNames) -> CachedMapperT: key = self.get_cache_key(expr) try: return self._cache[key] @@ -218,9 +217,7 @@ class CachedMapper(Mapper, Generic[CachedMapperT]): return result # type: ignore[no-any-return] if TYPE_CHECKING: - # type-ignore-reason: incompatible with super class - def __call__(self, expr: ArrayOrNames # type: ignore[override] - ) -> CachedMapperT: + def __call__(self, expr: ArrayOrNames) -> CachedMapperT: return self.rec(expr) # }}} @@ -240,15 +237,10 @@ class CopyMapper(CachedMapper[ArrayOrNames]): This does not copy the data of a :class:`pytato.array.DataWrapper`. """ if TYPE_CHECKING: - # type-ignore-reason: specialized variant of super-class' rec method - def rec(self, # type: ignore[override] - expr: CopyMapperResultT) -> CopyMapperResultT: - # type-ignore-reason: CachedMapper.rec's return type is imprecise - return super().rec(expr) # type: ignore[return-value] - - # type-ignore-reason: specialized variant of super-class' rec method - def __call__(self, # type: ignore[override] - expr: CopyMapperResultT) -> CopyMapperResultT: + def rec(self, expr: CopyMapperResultT) -> CopyMapperResultT: + return super().rec(expr) + + def __call__(self, expr: CopyMapperResultT) -> CopyMapperResultT: return self.rec(expr) def clone_for_callee(self: _SelfMapper) -> _SelfMapper: @@ -1192,17 +1184,13 @@ class TopoSortMapper(CachedWalkMapper): super().__init__() self.topological_order: List[Array] = [] - # type-ignore-reason: dropped the extra `*args, **kwargs`. - def get_cache_key(self, expr: ArrayOrNames) -> int: # type: ignore[override] + def get_cache_key(self, expr: ArrayOrNames) -> int: return id(expr) - # type-ignore-reason: dropped the extra `*args, **kwargs`. - def post_visit(self, expr: Any) -> None: # type: ignore[override] + def post_visit(self, expr: Any) -> None: self.topological_order.append(expr) - # type-ignore-reason: dropped the extra `*args, **kwargs`. - def map_function_definition(self, # type: ignore[override] - expr: FunctionDefinition) -> None: + def map_function_definition(self, expr: FunctionDefinition) -> None: # do nothing as it includes arrays from a different namespace. return @@ -1226,8 +1214,7 @@ class CachedMapAndCopyMapper(CopyMapper): # than Mapper.__init__ and does not have map_fn return type(self)(self.map_fn) # type: ignore[call-arg,attr-defined] - # type-ignore-reason:incompatible with Mapper.rec() - def rec(self, expr: MappedT) -> MappedT: # type: ignore[override] + def rec(self, expr: MappedT) -> MappedT: if expr in self._cache: # type-ignore-reason: parametric Mapping types aren't a thing return self._cache[expr] # type: ignore[return-value] @@ -1238,8 +1225,7 @@ class CachedMapAndCopyMapper(CopyMapper): return result # type: ignore[return-value] if TYPE_CHECKING: - # type-ignore-reason: Mapper.__call__ returns Any - def __call__(self, expr: MappedT) -> MappedT: # type: ignore[override] + def __call__(self, expr: MappedT) -> MappedT: return self.rec(expr) # }}} diff --git a/pytato/transform/einsum_distributive_law.py b/pytato/transform/einsum_distributive_law.py index 9ce210a..9098ee9 100644 --- a/pytato/transform/einsum_distributive_law.py +++ b/pytato/transform/einsum_distributive_law.py @@ -147,8 +147,7 @@ class EinsumDistributiveLawMapper(Mapper): Optional[_EinsumDistributiveLawMapperContext]]: return (expr, ctx) - # type-ignore-reason: incompatible with superclass - def rec(self, # type: ignore[override] + def rec(self, expr: MappedT, ctx: Optional[_EinsumDistributiveLawMapperContext] ) -> MappedT: @@ -161,8 +160,7 @@ class EinsumDistributiveLawMapper(Mapper): # type-ignore-reason: Mapper.rec has imprecise func. signature return result # type: ignore[no-any-return] - # type-ignore-reason: incompatible with super class - def __call__(self, # type: ignore[override] + def __call__(self, expr: MappedT, ctx: Optional[_EinsumDistributiveLawMapperContext], ) -> MappedT: diff --git a/pytato/transform/lower_to_index_lambda.py b/pytato/transform/lower_to_index_lambda.py index ad16fac..f31200d 100644 --- a/pytato/transform/lower_to_index_lambda.py +++ b/pytato/transform/lower_to_index_lambda.py @@ -470,7 +470,7 @@ class ToIndexLambdaMixin: class ToIndexLambdaMapper(Mapper, ToIndexLambdaMixin): - def handle_unsupported_array(self, expr: Any) -> Any: # type: ignore[override] + def handle_unsupported_array(self, expr: Any) -> Any: raise CannotBeLoweredToIndexLambda(type(expr)) def rec(self, expr: Array) -> Array: # type: ignore[override] diff --git a/pytato/transform/metadata.py b/pytato/transform/metadata.py index ff3cd2d..5b2075b 100644 --- a/pytato/transform/metadata.py +++ b/pytato/transform/metadata.py @@ -175,8 +175,7 @@ class AxesTagsEquationCollector(Mapper): # {{{ mapper interface - # type-ignore reason: signature not compatible with Mapper.rec - def rec(self, expr: ArrayOrNames) -> None: # type: ignore[override] + def rec(self, expr: ArrayOrNames) -> None: if expr in self._visited_nodes: return @@ -595,8 +594,7 @@ class AxisTagAttacher(CopyMapper): self.axis_to_tags: Mapping[Tuple[Array, int], Iterable[Tag]] = axis_to_tags self.tag_corresponding_redn_descr: bool = tag_corresponding_redn_descr - # type-ignore reason: overrides the type of Mapper.rec - def rec(self, expr: ArrayOrNames) -> Any: # type: ignore[override] + def rec(self, expr: ArrayOrNames) -> Any: if isinstance(expr, (AbstractResultWithNamedArrays, DistributedSendRefHolder)): return super().rec(expr) diff --git a/pytato/visualization/dot.py b/pytato/visualization/dot.py index 32a2ae5..d84b3aa 100644 --- a/pytato/visualization/dot.py +++ b/pytato/visualization/dot.py @@ -184,8 +184,7 @@ class ArrayToDotNodeInfoMapper(CachedMapper[ArrayOrNames]): # Default handler, does its best to guess how to handle fields. info = self.get_common_dot_info(expr) - # type-ignore-reason: https://github.com/python/mypy/issues/16254 - for field in attrs.fields(type(expr)): # type: ignore[misc] + for field in attrs.fields(type(expr)): if field.name in info.fields: continue attr = getattr(expr, field.name) -- GitLab