Coverage for nilearn/typing.py: 66%
81 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-18 13:00 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-18 13:00 +0200
1"""Types or Type aliases used by Nilearn.
3Many of those correspond to the types of variable
4declared in nilearn._utils.doc.
6Several of them can be enforced at run time using
7nilearn._utils.param_validaton.check_params.
9To expand the functionality of check_params you need to:
11- describe the expected type for that parameter / attribute
12 in this module ``nilearn.typing``
13 It must be something that ``isinstance`` can handle.
15- expand the ``type_map`` dictionary of ``check_params``
16 to pair the name of the parameter / attribute with its expected type.
17"""
19from __future__ import annotations
21import pathlib
22import sys
23from pathlib import Path
24from typing import Callable
26import numpy as np
27from joblib.memory import Memory
28from nibabel import Nifti1Image
29from numpy import ndarray
30from numpy.typing import DTypeLike
32Annotate = bool
33BgOnData = bool
34ColorBar = bool
35Connected = bool
36Detrend = bool
37DrawCross = bool
38KeepMaskedLabels = bool
39KeepMaskedMaps = bool
40NiimgLike = (Nifti1Image, str, Path)
41Radiological = bool
42Resume = bool
43Standardize = bool
44StandardizeConfounds = bool
45Tfce = bool
46TwoSidedTest = bool
49# TODO update when dropping python 3.9
50if sys.version_info[1] < 10: 50 ↛ 51line 50 didn't jump to line 51 because the condition on line 50 was never true
51 BorderSize = (int, np.integer)
52 DataDir = (str, pathlib.Path)
53 DType = DTypeLike
54 HighPass = (float, int, np.floating, np.integer)
55 HrfModel = (str, Callable, list)
56 LowPass = (float, int, np.floating, np.integer)
57 LowerCutoff = (float, np.floating)
58 MemoryLevel = (int, np.integer)
59 MemoryLike = (Memory, str, pathlib.Path)
60 NJobs = (int, np.integer)
61 NPerm = (int, np.integer)
62 Opening = (bool, int, np.integer)
63 RandomState = (int, np.integer, np.random.RandomState)
64 Resolution = (int, np.integer)
65 SmoothingFwhm = (float, int, np.floating, np.integer)
66 TargetAffine = ndarray
67 TargetShape = (tuple, list)
68 Threshold = (float, int, str, np.floating, np.integer)
69 Title = str
70 Tr = (float, int)
71 Transparency = (
72 float,
73 int,
74 np.floating,
75 np.integer,
76 str,
77 Path,
78 Nifti1Image,
79 Path,
80 )
81 TransparencyRange = (list, tuple)
82 Url = str
83 UpperCutoff = (float, np.floating)
84 Verbose = (int, np.integer)
85 Vmin = (float, int, np.floating, np.integer)
86 Vmax = (float, int, np.floating, np.integer)
89else:
90 from typing import TypeAlias
92 BorderSize: TypeAlias = int | np.integer
93 DataDir: TypeAlias = str | pathlib.Path | None
94 DType: TypeAlias = DTypeLike | None
96 # Note that for HrfModel
97 # str is too generic here
98 # and it should actually be Literal["spm", "glover", ...]
99 # if we wanted to use proper type annotation
100 HrfModel: TypeAlias = str | Callable | list | None
102 HighPass: TypeAlias = float | int | np.floating | np.integer | None
103 LowerCutoff: TypeAlias = float | np.floating
104 LowPass: TypeAlias = float | int | np.floating | np.integer | None
105 MemoryLike: TypeAlias = Memory | str | pathlib.Path | None
106 MemoryLevel: TypeAlias = int | np.integer
107 NJobs: TypeAlias = int | np.integer
108 NPerm: TypeAlias = int | np.integer
109 RandomState = int | np.floating | np.integer | np.random.RandomState | None
110 Opening: TypeAlias = bool | int | np.integer
111 Resolution: TypeAlias = int | np.integer | None
112 SmoothingFwhm: TypeAlias = float | int | np.floating | np.integer | None
113 TargetAffine: TypeAlias = ndarray | None
115 # Note that this is usable as for static type checking,
116 # as type checkers will complain1
117 # about using a generic and would prefer "list[int]" to "list".
118 TargetShape: TypeAlias = tuple | list | None
120 # str is too generic: should be Literal["auto"]
121 Threshold: TypeAlias = float | int | np.floating | np.integer | str | None
123 Title: TypeAlias = str | None
124 Tr: TypeAlias = float | int | np.floating | np.integer | None
125 Transparency: TypeAlias = (
126 float
127 | int
128 | np.floating
129 | np.integer
130 | str
131 | Path
132 | Nifti1Image
133 | Path
134 | None
135 )
136 TransparencyRange: TypeAlias = list | tuple | None
137 Url: TypeAlias = str | None
138 UpperCutoff: TypeAlias = float | np.floating
139 Verbose: TypeAlias = int | np.integer
140 Vmin = float | int | np.floating | np.integer | None
141 Vmax = float | int | np.floating | np.integer | None