module documentation

Undocumented

Function check_dir Returns a mapping of all objects with the wrong __module__ attribute.
Function is_unexpected Check if this needs to be considered.
Function test_all_modules_are_expected Test that we don't add anything that looks like a new public module by accident. Check is based on filenames.
Function test_all_modules_are_expected_2 Method checking all objects. The pkgutil-based method in test_all_modules_are_expected does not catch imports into a namespace, only filenames. So this test is more thorough, and checks this like:
Function test_api_importable Check that all submodules listed higher up in this file can be imported
Function test_array_api_entry_point Entry point for Array API implementation can be found with importlib and returns the numpy.array_api namespace.
Function test_dir_testing Assert that output of dir has only one "testing/tester" attribute without duplicate
Function test_import_lazy_import Make sure we can actually use the modules we lazy load.
Function test_NPY_NO_EXPORT Undocumented
Function test_numpy_fft Undocumented
Function test_numpy_linalg Undocumented
Function test_numpy_namespace Undocumented
Constant PRIVATE_BUT_PRESENT_MODULES Undocumented
Constant PUBLIC_ALIASED_MODULES Undocumented
Constant PUBLIC_MODULES Undocumented
Constant SKIP_LIST Undocumented
Constant SKIP_LIST_2 Undocumented
def check_dir(module, module_name=None): (source)

Returns a mapping of all objects with the wrong __module__ attribute.

def is_unexpected(name): (source)

Check if this needs to be considered.

def test_all_modules_are_expected(): (source)

Test that we don't add anything that looks like a new public module by accident. Check is based on filenames.

def test_all_modules_are_expected_2(): (source)

Method checking all objects. The pkgutil-based method in test_all_modules_are_expected does not catch imports into a namespace, only filenames. So this test is more thorough, and checks this like:

import .lib.scimath as emath

To check if something in a module is (effectively) public, one can check if there's anything in that namespace that's a public function/object but is not exposed in a higher-level namespace. For example for a numpy.lib submodule:

mod = np.lib.mixins
for obj in mod.__all__:
    if obj in np.__all__:
        continue
    elif obj in np.lib.__all__:
        continue

    else:
        print(obj)
def test_api_importable(): (source)

Check that all submodules listed higher up in this file can be imported

Note that if a PRIVATE_BUT_PRESENT_MODULES entry goes missing, it may simply need to be removed from the list (deprecation may or may not be needed - apply common sense).

@pytest.mark.xfail((sysconfig.get_config_var('Py_DEBUG') is not None), reason='NumPy possibly built with `USE_DEBUG=True ./tools/travis-test.sh`, which does not expose the `array_api` entry point. See https://github.com/numpy/numpy/pull/19800')
def test_array_api_entry_point(): (source)

Entry point for Array API implementation can be found with importlib and returns the numpy.array_api namespace.

def test_dir_testing(): (source)

Assert that output of dir has only one "testing/tester" attribute without duplicate

@pytest.mark.skipif(IS_WASM, reason='can\'t start subprocess')
@pytest.mark.parametrize('name', ['testing', 'Tester'])
def test_import_lazy_import(name): (source)

Make sure we can actually use the modules we lazy load.

While not exported as part of the public API, it was accessible. With the use of __getattr__ and __dir__, this isn't always true It can happen that an infinite recursion may happen.

This is the only way I found that would force the failure to appear on the badly implemented code.

We also test for the presence of the lazily imported modules in dir

@pytest.mark.skipif((ctypes is None), reason='ctypes not available in this python')
def test_NPY_NO_EXPORT(): (source)

Undocumented

def test_numpy_fft(): (source)

Undocumented

def test_numpy_linalg(): (source)

Undocumented

def test_numpy_namespace(): (source)

Undocumented

PRIVATE_BUT_PRESENT_MODULES = (source)

Undocumented

Value
[('numpy.' + s) for s in ['compat', 'compat.py3k', 'conftest', 'core',
    'core.arrayprint', 'core.defchararray', 'core.einsumfunc',
    'core.fromnumeric', 'core.function_base', 'core.getlimits',
    'core.memmap', 'core.multiarray', 'core.numeric', 'core.numerictypes',
    'core.overrides', 'core.records', 'core.shape_base', 'core.umath',
    'core.umath_tests', 'distutils.armccompiler', 'distutils.ccompiler',
    'distutils.ccompiler_opt', 'distutils.command',
...
PUBLIC_ALIASED_MODULES: list[str] = (source)

Undocumented

Value
['numpy.char', 'numpy.emath', 'numpy.rec']
PUBLIC_MODULES = (source)

Undocumented

Value
[('numpy.' + s) for s in ['array_api', 'array_api.linalg', 'ctypeslib',
    'distutils', 'distutils.cpuinfo', 'distutils.exec_command',
    'distutils.misc_util', 'distutils.log', 'distutils.system_info', 'doc',
    'doc.constants', 'doc.ufuncs', 'f2py', 'fft', 'lib', 'lib.format',
    'lib.mixins', 'lib.recfunctions', 'lib.scimath', 'lib.stride_tricks',
    'linalg', 'ma', 'ma.extras', 'ma.mrecords', 'matlib', 'polynomial',
    'polynomial.chebyshev', 'polynomial.hermite', 'polynomial.hermite_e',
...
SKIP_LIST: list[str] = (source)

Undocumented

Value
['numpy.core.code_generators',
 'numpy.core.code_generators.genapi',
 'numpy.core.code_generators.generate_umath',
 'numpy.core.code_generators.ufunc_docstrings',
 'numpy.core.code_generators.generate_numpy_api',
 'numpy.core.code_generators.generate_ufunc_api',
 'numpy.core.code_generators.numpy_api',
...
SKIP_LIST_2: list[str] = (source)

Undocumented

Value
['numpy.math',
 'numpy.distutils.log.sys',
 'numpy.distutils.log.logging',
 'numpy.distutils.log.warnings',
 'numpy.doc.constants.re',
 'numpy.doc.constants.textwrap',
 'numpy.lib.emath',
...