MCPcopy Create free account
hub / github.com/numpy/numpy / __getattr__

Function __getattr__

numpy/__init__.py:290–334  ·  view source on GitHub ↗
(attr)

Source from the content-addressed store, hash-verified

288 numarray = 'removed'
289
290 def __getattr__(attr):
291 # Warn for expired attributes, and return a dummy function
292 # that always raises an exception.
293 import warnings
294 import math
295 try:
296 msg = __expired_functions__[attr]
297 except KeyError:
298 pass
299 else:
300 warnings.warn(msg, DeprecationWarning, stacklevel=2)
301
302 def _expired(*args, **kwds):
303 raise RuntimeError(msg)
304
305 return _expired
306
307 # Emit warnings for deprecated attributes
308 try:
309 val, msg = __deprecated_attrs__[attr]
310 except KeyError:
311 pass
312 else:
313 warnings.warn(msg, DeprecationWarning, stacklevel=2)
314 return val
315
316 if attr in __future_scalars__:
317 # And future warnings for those that will change, but also give
318 # the AttributeError
319 warnings.warn(
320 f"In the future `np.{attr}` will be defined as the "
321 "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
322
323 if attr in __former_attrs__:
324 raise AttributeError(__former_attrs__[attr])
325
326 if attr == 'testing':
327 import numpy.testing as testing
328 return testing
329 elif attr == 'Tester':
330 "Removed in NumPy 1.25.0"
331 raise RuntimeError("Tester was removed in NumPy 1.25.")
332
333 raise AttributeError("module {!r} has no attribute "
334 "{!r}".format(__name__, attr))
335
336 def __dir__():
337 public_symbols = globals().keys() | {'testing'}

Callers

nothing calls this directly

Calls 1

warnMethod · 0.80

Tested by

no test coverage detected