Skip to content

Commit 0f8854f

Browse files
Armavicavandalt
authored andcommitted
Precise blanket type ignore and noqa statements
1 parent 8f4ad70 commit 0f8854f

File tree

26 files changed

+60
-62
lines changed

26 files changed

+60
-62
lines changed

pymc/backends/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@
8585
RunType: TypeAlias = Run
8686
HAS_MCB = True
8787
except ImportError:
88-
TraceOrBackend = BaseTrace # type: ignore
89-
RunType = type(None) # type: ignore
88+
TraceOrBackend = BaseTrace # type: ignore[misc]
89+
RunType = type(None) # type: ignore[assignment, misc]
9090

9191

9292
__all__ = ["to_inference_data", "predictions_to_inference_data"]

pymc/distributions/shape_utils.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,13 @@ def change_dist_size(
254254
255255
"""
256256
# Check the dimensionality of the `new_size` kwarg
257-
new_size_ndim = np.ndim(new_size) # type: ignore
257+
new_size_ndim = np.ndim(new_size) # type: ignore[arg-type]
258258
if new_size_ndim > 1:
259259
raise ShapeError("The `new_size` must be ≤1-dimensional.", actual=new_size_ndim)
260260
elif new_size_ndim == 0:
261-
new_size = (new_size,) # type: ignore
261+
new_size = (new_size,) # type: ignore[assignment]
262262
else:
263-
new_size = tuple(new_size) # type: ignore
263+
new_size = tuple(new_size) # type: ignore[arg-type]
264264

265265
op = dist.owner.op
266266
new_dist = _change_dist_size(op, dist, new_size=new_size, expand=expand)
@@ -325,7 +325,7 @@ def change_specify_shape_size(op, ss, new_size, expand) -> TensorVariable:
325325
new_shapes[-ndim_supp:] = shapes[-ndim_supp:]
326326

327327
# specify_shape has a wrong signature https://github.com/aesara-devs/aesara/issues/1164
328-
return pt.specify_shape(new_var, new_shapes) # type: ignore
328+
return pt.specify_shape(new_var, new_shapes) # type: ignore[arg-type]
329329

330330

331331
def get_support_shape(
@@ -389,8 +389,7 @@ def get_support_shape(
389389
raise ValueError(f"Number of dims is too small for ndim_supp of {ndim_supp}")
390390
model = modelcontext(None)
391391
inferred_support_shape = [
392-
model.dim_lengths[dims[i]] - support_shape_offset[i] # type: ignore
393-
for i in np.arange(-ndim_supp, 0)
392+
model.dim_lengths[dims[i]] - support_shape_offset[i] for i in np.arange(-ndim_supp, 0)
394393
]
395394

396395
if inferred_support_shape is None and observed is not None:

pymc/distributions/simulator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def __new__(cls, name, *args, **kwargs):
144144
return super().__new__(cls, name, *args, **kwargs)
145145

146146
@classmethod
147-
def dist( # type: ignore
147+
def dist( # type: ignore[override]
148148
cls,
149149
fn,
150150
*unnamed_params,
@@ -256,7 +256,7 @@ def rv_op(
256256
return sim_op(*params, **kwargs)
257257

258258

259-
@_support_point.register(SimulatorRV) # type: ignore
259+
@_support_point.register(SimulatorRV)
260260
def simulator_support_point(op, rv, *inputs):
261261
sim_inputs = op.dist_params(rv.owner)
262262
# Take the mean of 10 draws

pymc/distributions/transforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
# ignore mypy error because it somehow considers that
2323
# "numpy.core.numeric has no attribute normalize_axis_tuple"
24-
from numpy.core.numeric import normalize_axis_tuple # type: ignore
24+
from numpy.core.numeric import normalize_axis_tuple # type: ignore[attr-defined]
2525
from pytensor.graph import Op
2626
from pytensor.tensor import TensorVariable
2727

pymc/gp/cov.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def __array_wrap__(self, result):
143143

144144
@staticmethod
145145
def _alloc(X, *shape: int) -> TensorVariable:
146-
return pt.alloc(X, *shape) # type: ignore
146+
return pt.alloc(X, *shape) # type: ignore[return-value]
147147

148148

149149
class Covariance(BaseCovariance):

pymc/gp/hsgp_approx.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ def prior(
432432
gp_dims: str | None = None,
433433
*args,
434434
**kwargs,
435-
): # type: ignore
435+
):
436436
R"""
437437
Return the (approximate) GP prior distribution evaluated over the input locations `X`.
438438
@@ -496,7 +496,7 @@ def _build_conditional(self, Xnew):
496496
elif self._parametrization == "centered":
497497
return self.mean_func(Xnew) + phi[:, i:] @ beta
498498

499-
def conditional(self, name: str, Xnew: TensorLike, dims: str | None = None): # type: ignore
499+
def conditional(self, name: str, Xnew: TensorLike, dims: str | None = None): # type: ignore[override]
500500
R"""
501501
Return the (approximate) conditional distribution evaluated over new input locations `Xnew`.
502502
@@ -695,7 +695,7 @@ def prior_linearized(self, X: TensorLike):
695695
psd = self.scale * self.cov_func.power_spectral_density_approx(J)
696696
return (phi_cos, phi_sin), psd
697697

698-
def prior(self, name: str, X: TensorLike, dims: str | None = None): # type: ignore
698+
def prior(self, name: str, X: TensorLike, dims: str | None = None): # type: ignore[override]
699699
R"""
700700
Return the (approximate) GP prior distribution evaluated over the input locations `X`.
701701
@@ -718,8 +718,8 @@ def prior(self, name: str, X: TensorLike, dims: str | None = None): # type: ign
718718
# and so does not contribute to the approximation.
719719
f = (
720720
self.mean_func(X)
721-
+ phi_cos @ (psd * self._beta[:m]) # type: ignore
722-
+ phi_sin[..., 1:] @ (psd[1:] * self._beta[m:]) # type: ignore
721+
+ phi_cos @ (psd * self._beta[:m]) # type: ignore[index]
722+
+ phi_sin[..., 1:] @ (psd[1:] * self._beta[m:]) # type: ignore[index]
723723
)
724724

725725
self.f = pm.Deterministic(name, f, dims=dims)
@@ -747,7 +747,7 @@ def _build_conditional(self, Xnew):
747747
phi = phi_cos @ (psd * beta[:m]) + phi_sin[..., 1:] @ (psd[1:] * beta[m:])
748748
return self.mean_func(Xnew) + phi
749749

750-
def conditional(self, name: str, Xnew: TensorLike, dims: str | None = None): # type: ignore
750+
def conditional(self, name: str, Xnew: TensorLike, dims: str | None = None): # type: ignore[override]
751751
R"""
752752
Return the (approximate) conditional distribution evaluated over new input locations `Xnew`.
753753

pymc/logprob/basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ def transformed_conditional_logp(
589589
}
590590
if values_to_transforms:
591591
# There seems to be an incorrect type hint in TransformValuesRewrite
592-
transform_rewrite = TransformValuesRewrite(values_to_transforms) # type: ignore
592+
transform_rewrite = TransformValuesRewrite(values_to_transforms) # type: ignore[arg-type]
593593

594594
kwargs.setdefault("warn_rvs", False)
595595
temp_logp_terms = conditional_logp(

pymc/logprob/tensor.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3535
# SOFTWARE.
3636

37-
3837
from pathlib import Path
3938

4039
from pytensor import tensor as pt
@@ -165,7 +164,7 @@ def find_measurable_stacks(fgraph, node) -> list[TensorVariable] | None:
165164
# the IR construction
166165
replacements = [(base_var, promised_valued_rv(base_var)) for base_var in base_vars]
167166
temp_fgraph = FunctionGraph(outputs=base_vars, clone=False)
168-
toposort_replace(temp_fgraph, replacements) # type: ignore
167+
toposort_replace(temp_fgraph, replacements) # type: ignore[arg-type]
169168
new_base_vars = temp_fgraph.outputs
170169

171170
if is_join:
@@ -182,7 +181,7 @@ class MeasurableDimShuffle(MeasurableOp, DimShuffle):
182181

183182
# Need to get the absolute path of `c_func_file`, otherwise it tries to
184183
# find it locally and fails when a new `Op` is initialized
185-
c_func_file = str(DimShuffle.get_path(Path(DimShuffle.c_func_file)))
184+
c_func_file = str(DimShuffle.get_path(Path(DimShuffle.c_func_file))) # type: ignore[arg-type]
186185

187186

188187
@_logprob.register(MeasurableDimShuffle)

pymc/model/transform/optimization.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ def freeze_dims_and_data(
7777
if isinstance(datum, SharedVariable)
7878
}
7979

80-
old_outs, old_coords, old_dim_lenghts = fg.outputs, fg._coords, fg._dim_lengths # type: ignore
80+
old_outs, old_coords, old_dim_lenghts = fg.outputs, fg._coords, fg._dim_lengths # type: ignore[attr-defined]
8181
# Rebuild strict will force the recreation of RV nodes with updated static types
82-
new_outs = clone_replace(old_outs, replace=frozen_replacements, rebuild_strict=False) # type: ignore
82+
new_outs = clone_replace(old_outs, replace=frozen_replacements, rebuild_strict=False) # type: ignore[arg-type]
8383
for old_out, new_out in zip(old_outs, new_outs):
8484
new_out.name = old_out.name
8585
fg = FunctionGraph(outputs=new_outs, clone=False)
86-
fg._coords = old_coords # type: ignore
87-
fg._dim_lengths = { # type: ignore
86+
fg._coords = old_coords # type: ignore[attr-defined]
87+
fg._dim_lengths = { # type: ignore[attr-defined]
8888
dim: frozen_replacements.get(dim_length, dim_length)
8989
for dim, dim_length in old_dim_lenghts.items()
9090
}
@@ -99,7 +99,7 @@ def freeze_dims_and_data(
9999
if transform is None:
100100
new_value = rv.type()
101101
else:
102-
new_value = transform.forward(rv, *rv.owner.inputs).type() # type: ignore
102+
new_value = transform.forward(rv, *rv.owner.inputs).type() # type: ignore[arg-type]
103103
new_value.name = old_value.name
104104
replacements[old_value] = new_value
105105
fg.replace_all(tuple(replacements.items()), import_missing=True)

pymc/model_graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def _make_node(
234234
kwargs["cluster"] = cluster
235235

236236
var_name: str = cast(str, node.var.name)
237-
add_node(var_name.replace(":", "&"), **kwargs) # type: ignore
237+
add_node(var_name.replace(":", "&"), **kwargs) # type: ignore[call-arg]
238238

239239

240240
class ModelGraph:

0 commit comments

Comments
 (0)