|
166 | 166 | # now that numpy modules are imported, can initialize limits
|
167 | 167 | core.getlimits._register_known_types()
|
168 | 168 |
|
| 169 | + __all__.extend(['bool', 'int', 'float', 'complex', 'object', 'unicode', |
| 170 | + 'str']) |
| 171 | + |
169 | 172 | __all__.extend(['__version__', 'show_config'])
|
170 | 173 | __all__.extend(core.__all__)
|
171 | 174 | __all__.extend(_mat.__all__)
|
|
182 | 185 | oldnumeric = 'removed'
|
183 | 186 | numarray = 'removed'
|
184 | 187 |
|
185 |
| - # We don't actually use this ourselves anymore, but I'm not 100% sure that |
186 |
| - # no-one else in the world is using it (though I hope not) |
187 |
| - from .testing import Tester |
| 188 | + if sys.version_info[:2] >= (3, 7): |
| 189 | + # Importing Tester requires importing all of UnitTest which is not a |
| 190 | + # cheap import Since it is mainly used in test suits, we lazy import it |
| 191 | + # here to save on the order of 10 ms of import time for most users |
| 192 | + # |
| 193 | + # The previous way Tester was imported also had a side effect of adding |
| 194 | + # the full `numpy.testing` namespace |
| 195 | + # |
| 196 | + # module level getattr is only supported in 3.7 onwards |
| 197 | + # https://www.python.org/dev/peps/pep-0562/ |
| 198 | + def __getattr__(attr): |
| 199 | + if attr == 'testing': |
| 200 | + import numpy.testing as testing |
| 201 | + return testing |
| 202 | + elif attr == 'Tester': |
| 203 | + from .testing import Tester |
| 204 | + return Tester |
| 205 | + else: |
| 206 | + raise AttributeError( |
| 207 | + "module %s has no attribute $s".format(__name__, attr)) |
| 208 | + |
| 209 | + |
| 210 | + def __dir__(): |
| 211 | + return __all__ + ['Tester', 'testing'] |
| 212 | + |
| 213 | + else: |
| 214 | + # We don't actually use this ourselves anymore, but I'm not 100% sure that |
| 215 | + # no-one else in the world is using it (though I hope not) |
| 216 | + from .testing import Tester |
188 | 217 |
|
189 | 218 | # Pytest testing
|
190 | 219 | from numpy._pytesttester import PytestTester
|
|
0 commit comments