From 9c342449691e54efbb9b0f4e3bab9d4e4a8d3986 Mon Sep 17 00:00:00 2001 From: jlnav Date: Wed, 11 Mar 2026 12:21:01 -0500 Subject: [PATCH] adjusts to please mypy, add mypy to precommit --- .pre-commit-config.yaml | 5 +++++ libensemble/utils/misc.py | 8 ++++---- pixi.lock | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index de927cff8..515439b2b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,3 +32,8 @@ repos: additional_dependencies: [black==22.12.0] files: ^(.*\.py|.*\.rst)$ args: [--line-length=120] + +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.19.1 + hooks: + - id: mypy diff --git a/libensemble/utils/misc.py b/libensemble/utils/misc.py index c4327dd02..6e3779910 100644 --- a/libensemble/utils/misc.py +++ b/libensemble/utils/misc.py @@ -4,7 +4,6 @@ from itertools import chain, groupby from operator import itemgetter -from typing import List import numpy as np import numpy.typing as npt @@ -85,6 +84,7 @@ def _get_combinable_multidim_names(first: dict, new_dtype_names: list) -> list: def _decide_dtype(name: str, entry, size: int) -> tuple: """decide dtype of field, and size if needed""" + output_type: str | type # str for numpy string type, type for python type if isinstance(entry, str): # use numpy style for string type output_type = "U" + str(len(entry) + 1) else: @@ -115,7 +115,7 @@ def _pack_field(input_dict: dict, field_names: list) -> tuple: return tuple(input_dict[name] for name in field_names) if len(field_names) > 1 else input_dict[field_names[0]] -def list_dicts_to_np(list_dicts: list, dtype: list = None, mapping: dict = {}) -> npt.NDArray: +def list_dicts_to_np(list_dicts: list, dtype: list | None = None, mapping: dict = {}) -> npt.NDArray: """Convert list of dicts to numpy structured array""" if list_dicts is None: return None @@ -231,7 +231,7 @@ def map_numpy_array(array: npt.NDArray, mapping: dict = {}) -> npt.NDArray: return array # Create new dtype with mapped fields - new_fields = [] + new_fields: list[tuple] = [] # Track fields processed by mapping to avoid duplication mapped_source_fields = set() @@ -275,7 +275,7 @@ def map_numpy_array(array: npt.NDArray, mapping: dict = {}) -> npt.NDArray: return mapped_array -def np_to_list_dicts(array: npt.NDArray, mapping: dict = {}) -> List[dict]: +def np_to_list_dicts(array: npt.NDArray, mapping: dict = {}) -> list[dict]: """Convert numpy structured array to list of dicts""" out = [] diff --git a/pixi.lock b/pixi.lock index 7ecb5aabd..f93bbb6a2 100644 --- a/pixi.lock +++ b/pixi.lock @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e6c850dcd99a7481c401b3f7be69d1519994aaad0416880955acd41f2603082d +oid sha256:ce81e3ca628ccd7f7370c1e3aeb11e3f5eb4da0ad3d4c809acf22c91c1ff7159 size 1156243