Skip to content

Commit 250ada5

Browse files
authored
Merge pull request #1693 from Libensemble/fix/mypy
Fix/mypy
2 parents a5a9deb + 1000202 commit 250ada5

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ repos:
3232
additional_dependencies: [black==22.12.0]
3333
files: ^(.*\.py|.*\.rst)$
3434
args: [--line-length=120]
35+
36+
- repo: https://github.com/pre-commit/mirrors-mypy
37+
rev: v1.19.1
38+
hooks:
39+
- id: mypy

libensemble/utils/misc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from itertools import chain, groupby
66
from operator import itemgetter
7-
from typing import List
87

98
import numpy as np
109
import numpy.typing as npt
@@ -85,6 +84,7 @@ def _get_combinable_multidim_names(first: dict, new_dtype_names: list) -> list:
8584

8685
def _decide_dtype(name: str, entry, size: int) -> tuple:
8786
"""decide dtype of field, and size if needed"""
87+
output_type: str | type # str for numpy string type, type for python type
8888
if isinstance(entry, str): # use numpy style for string type
8989
output_type = "U" + str(len(entry) + 1)
9090
else:
@@ -115,7 +115,7 @@ def _pack_field(input_dict: dict, field_names: list) -> tuple:
115115
return tuple(input_dict[name] for name in field_names) if len(field_names) > 1 else input_dict[field_names[0]]
116116

117117

118-
def list_dicts_to_np(list_dicts: list, dtype: list = None, mapping: dict = {}) -> npt.NDArray:
118+
def list_dicts_to_np(list_dicts: list, dtype: list | None = None, mapping: dict = {}) -> npt.NDArray:
119119
"""Convert list of dicts to numpy structured array"""
120120
if list_dicts is None:
121121
return None
@@ -231,7 +231,7 @@ def map_numpy_array(array: npt.NDArray, mapping: dict = {}) -> npt.NDArray:
231231
return array
232232

233233
# Create new dtype with mapped fields
234-
new_fields = []
234+
new_fields: list[tuple] = []
235235

236236
# Track fields processed by mapping to avoid duplication
237237
mapped_source_fields = set()
@@ -275,7 +275,7 @@ def map_numpy_array(array: npt.NDArray, mapping: dict = {}) -> npt.NDArray:
275275
return mapped_array
276276

277277

278-
def np_to_list_dicts(array: npt.NDArray, mapping: dict = {}) -> List[dict]:
278+
def np_to_list_dicts(array: npt.NDArray, mapping: dict = {}) -> list[dict]:
279279
"""Convert numpy structured array to list of dicts"""
280280
out = []
281281

0 commit comments

Comments
 (0)