codekingpro/portable-devtools
115k
1import functools
2import importlib
3import inspect
4import pkgutil
5import subprocess
6import sys
7import sysconfig
8import types
9import warnings
10
11import pytest
12
13import numpy
14import numpy as np
15from numpy.testing import IS_WASM
16
17try:
18 import ctypes
19except ImportError:
20 ctypes = None
21
22
23def check_dir(module, module_name=None):
24 """Returns a mapping of all objects with the wrong __module__ attribute."""
25 if module_name is None:
26 module_name = module.__name__
27 results = {}
28 for name in dir(module):
29 if name == "core":
30 continue
31 item = getattr(module, name)
32 if (hasattr(item, '__module__') and hasattr(item, '__name__')
33 and item.__module__ != module_name):
34 results[name] = item.__module__ + '.' + item.__name__
35 return results
36
37
38def test_numpy_namespace():
39 # We override dir to not show these members
40 allowlist = {
41 'recarray': 'numpy.rec.recarray',
42 }
43 bad_results = check_dir(np)
44 # pytest gives better error messages with the builtin assert than with
45 # assert_equal
46 assert bad_results == allowlist
47
48
49@pytest.mark.skipif(IS_WASM, reason="can't start subprocess")
50@pytest.mark.parametrize('name', ['testing'])
51def test_import_lazy_import(name):
52 """Make sure we can actually use the modules we lazy load.
53
54 While not exported as part of the public API, it was accessible. With the
55 use of __getattr__ and __dir__, this isn't always true It can happen that
56 an infinite recursion may happen.
57
58 This is the only way I found that would force the failure to appear on the
59 badly implemented code.
60
61 We also test for the presence of the lazily imported modules in dir
62
63 """
64 exe = (sys.executable, '-c', "import numpy; numpy." + name)
65 result = subprocess.check_output(exe)
66 assert not result
67
68 # Make sure they are still in the __dir__
69 assert name in dir(np)
70
71
72def test_dir_testing():
73 """Assert that output of dir has only one "testing/tester"
74 attribute without duplicate"""
75 assert len(dir(np)) == len(set(dir(np)))
76
77
78def test_numpy_linalg():
79 bad_results = check_dir(np.linalg)
80 assert bad_results == {}
81
82
83def test_numpy_fft():
84 bad_results = check_dir(np.fft)
85 assert bad_results == {}
86
87
88@pytest.mark.skipif(ctypes is None,
89 reason="ctypes not available in this python")
90def test_NPY_NO_EXPORT():
91 cdll = ctypes.CDLL(np._core._multiarray_tests.__file__)
92 # Make sure an arbitrary NPY_NO_EXPORT function is actually hidden
93 f = getattr(cdll, 'test_not_exported', None)
94 assert f is None, ("'test_not_exported' is mistakenly exported, "
95 "NPY_NO_EXPORT does not work")
96
97
98# Historically NumPy has not used leading underscores for private submodules
99# much. This has resulted in lots of things that look like public modules
100# (i.e. things that can be imported as `import numpy.somesubmodule.somefile`),
101# but were never intended to be public. The PUBLIC_MODULES list contains
102# modules that are either public because they were meant to be, or because they
103# contain public functions/objects that aren't present in any other namespace
104# for whatever reason and therefore should be treated as public.
105#
106# The PRIVATE_BUT_PRESENT_MODULES list contains modules that look public (lack
107# of underscores) but should not be used. For many of those modules the
108# current status is fine. For others it may make sense to work on making them
109# private, to clean up our public API and avoid confusion.
110PUBLIC_MODULES = ['numpy.' + s for s in [
111 "ctypeslib",
112 "dtypes",
113 "exceptions",
114 "f2py",
115 "fft",
116 "lib",
117 "lib.array_utils",
118 "lib.format",
119 "lib.introspect",
120 "lib.mixins",
121 "lib.npyio",
122 "lib.recfunctions", # note: still needs cleaning, was forgotten for 2.0
123 "lib.scimath",
124 "lib.stride_tricks",
125 "linalg",
126 "ma",
127 "ma.extras",
128 "ma.mrecords",
129 "polynomial",
130 "polynomial.chebyshev",
131 "polynomial.hermite",
132 "polynomial.hermite_e",
133 "polynomial.laguerre",
134 "polynomial.legendre",
135 "polynomial.polynomial",
136 "random",
137 "strings",
138 "testing",
139 "testing.overrides",
140 "typing",
141 "typing.mypy_plugin",
142 "version",
143]]
144if sys.version_info < (3, 12):
145 PUBLIC_MODULES += [
146 'numpy.' + s for s in [
147 "distutils",
148 "distutils.cpuinfo",
149 "distutils.exec_command",
150 "distutils.misc_util",
151 "distutils.log",
152 "distutils.system_info",
153 ]
154 ]
155
156
157PUBLIC_ALIASED_MODULES = [
158 "numpy.char",
159 "numpy.emath",
160 "numpy.rec",
161]
162
163
164PRIVATE_BUT_PRESENT_MODULES = ['numpy.' + s for s in [
165 "conftest",
166 "core",
167 "core.multiarray",
168 "core.numeric",
169 "core.umath",
170 "core.arrayprint",
171 "core.defchararray",
172 "core.einsumfunc",
173 "core.fromnumeric",
174 "core.function_base",
175 "core.getlimits",
176 "core.numerictypes",
177 "core.overrides",
178 "core.records",
179 "core.shape_base",
180 "f2py.auxfuncs",
181 "f2py.capi_maps",
182 "f2py.cb_rules",
183 "f2py.cfuncs",
184 "f2py.common_rules",
185 "f2py.crackfortran",
186 "f2py.diagnose",
187 "f2py.f2py2e",
188 "f2py.f90mod_rules",
189 "f2py.func2subr",
190 "f2py.rules",
191 "f2py.symbolic",
192 "f2py.use_rules",
193 "lib.user_array", # note: not in np.lib, but probably should just be deleted
194 "linalg.lapack_lite",
195 "ma.core",
196 "ma.testutils",
197 "matlib",
198 "matrixlib",
199 "matrixlib.defmatrix",
200 "polynomial.polyutils",
201 "random.mtrand",
202 "random.bit_generator",
203 "testing.print_coercion_tables",
204]]
205if sys.version_info < (3, 12):
206 PRIVATE_BUT_PRESENT_MODULES += [
207 'numpy.' + s for s in [
208 "distutils.armccompiler",
209 "distutils.fujitsuccompiler",
210 "distutils.ccompiler",
211 'distutils.ccompiler_opt',
212 "distutils.command",
213 "distutils.command.autodist",
214 "distutils.command.bdist_rpm",
215 "distutils.command.build",
216 "distutils.command.build_clib",
217 "distutils.command.build_ext",
218 "distutils.command.build_py",
219 "distutils.command.build_scripts",
220 "distutils.command.build_src",
221 "distutils.command.config",
222 "distutils.command.config_compiler",
223 "distutils.command.develop",
224 "distutils.command.egg_info",
225 "distutils.command.install",
226 "distutils.command.install_clib",
227 "distutils.command.install_data",
228 "distutils.command.install_headers",
229 "distutils.command.sdist",
230 "distutils.conv_template",
231 "distutils.core",
232 "distutils.extension",
233 "distutils.fcompiler",
234 "distutils.fcompiler.absoft",
235 "distutils.fcompiler.arm",
236 "distutils.fcompiler.compaq",
237 "distutils.fcompiler.environment",
238 "distutils.fcompiler.g95",
239 "distutils.fcompiler.gnu",
240 "distutils.fcompiler.hpux",
241 "distutils.fcompiler.ibm",
242 "distutils.fcompiler.intel",
243 "distutils.fcompiler.lahey",
244 "distutils.fcompiler.mips",
245 "distutils.fcompiler.nag",
246 "distutils.fcompiler.none",
247 "distutils.fcompiler.pathf95",
248 "distutils.fcompiler.pg",
249 "distutils.fcompiler.nv",
250 "distutils.fcompiler.sun",
251 "distutils.fcompiler.vast",
252 "distutils.fcompiler.fujitsu",
253 "distutils.from_template",
254 "distutils.intelccompiler",
255 "distutils.lib2def",
256 "distutils.line_endings",
257 "distutils.mingw32ccompiler",
258 "distutils.msvccompiler",
259 "distutils.npy_pkg_config",
260 "distutils.numpy_distribution",
261 "distutils.pathccompiler",
262 "distutils.unixccompiler",
263 ]
264 ]
265
266
267def is_unexpected(name):
268 """Check if this needs to be considered."""
269 return (
270 '._' not in name and '.tests' not in name and '.setup' not in name
271 and name not in PUBLIC_MODULES
272 and name not in PUBLIC_ALIASED_MODULES
273 and name not in PRIVATE_BUT_PRESENT_MODULES
274 )
275
276
277if sys.version_info >= (3, 12):
278 SKIP_LIST = []
279else:
280 SKIP_LIST = ["numpy.distutils.msvc9compiler"]
281
282
283def test_all_modules_are_expected():
284 """
285 Test that we don't add anything that looks like a new public module by
286 accident. Check is based on filenames.
287 """
288
289 modnames = []
290 for _, modname, ispkg in pkgutil.walk_packages(path=np.__path__,
291 prefix=np.__name__ + '.',
292 onerror=None):
293 if is_unexpected(modname) and modname not in SKIP_LIST:
294 # We have a name that is new. If that's on purpose, add it to
295 # PUBLIC_MODULES. We don't expect to have to add anything to
296 # PRIVATE_BUT_PRESENT_MODULES. Use an underscore in the name!
297 modnames.append(modname)
298
299 if modnames:
300 raise AssertionError(f'Found unexpected modules: {modnames}')
301
302
303# Stuff that clearly shouldn't be in the API and is detected by the next test
304# below
305SKIP_LIST_2 = [
306 'numpy.lib.math',
307 'numpy.matlib.char',
308 'numpy.matlib.rec',
309 'numpy.matlib.emath',
310 'numpy.matlib.exceptions',
311 'numpy.matlib.math',
312 'numpy.matlib.linalg',
313 'numpy.matlib.fft',
314 'numpy.matlib.random',
315 'numpy.matlib.ctypeslib',
316 'numpy.matlib.ma',
317]
318if sys.version_info < (3, 12):
319 SKIP_LIST_2 += [
320 'numpy.distutils.log.sys',
321 'numpy.distutils.log.logging',
322 'numpy.distutils.log.warnings',
323 ]
324
325
326def test_all_modules_are_expected_2():
327 """
328 Method checking all objects. The pkgutil-based method in
329 `test_all_modules_are_expected` does not catch imports into a namespace,
330 only filenames. So this test is more thorough, and checks this like:
331
332 import .lib.scimath as emath
333
334 To check if something in a module is (effectively) public, one can check if
335 there's anything in that namespace that's a public function/object but is
336 not exposed in a higher-level namespace. For example for a `numpy.lib`
337 submodule::
338
339 mod = np.lib.mixins
340 for obj in mod.__all__:
341 if obj in np.__all__:
342 continue
343 elif obj in np.lib.__all__:
344 continue
345
346 else:
347 print(obj)
348
349 """
350
351 def find_unexpected_members(mod_name):
352 members = []
353 module = importlib.import_module(mod_name)
354 if hasattr(module, '__all__'):
355 objnames = module.__all__
356 else:
357 objnames = dir(module)
358
359 for objname in objnames:
360 if not objname.startswith('_'):
361 fullobjname = mod_name + '.' + objname
362 if isinstance(getattr(module, objname), types.ModuleType):
363 if is_unexpected(fullobjname):
364 if fullobjname not in SKIP_LIST_2:
365 members.append(fullobjname)
366
367 return members
368
369 unexpected_members = find_unexpected_members("numpy")
370 for modname in PUBLIC_MODULES:
371 unexpected_members.extend(find_unexpected_members(modname))
372
373 if unexpected_members:
374 raise AssertionError("Found unexpected object(s) that look like "
375 f"modules: {unexpected_members}")
376
377
378def test_api_importable():
379 """
380 Check that all submodules listed higher up in this file can be imported
381
382 Note that if a PRIVATE_BUT_PRESENT_MODULES entry goes missing, it may
383 simply need to be removed from the list (deprecation may or may not be
384 needed - apply common sense).
385 """
386 def check_importable(module_name):
387 try:
388 importlib.import_module(module_name)
389 except (ImportError, AttributeError):
390 return False
391
392 return True
393
394 module_names = []
395 for module_name in PUBLIC_MODULES:
396 if not check_importable(module_name):
397 module_names.append(module_name)
398
399 if module_names:
400 raise AssertionError("Modules in the public API that cannot be "
401 f"imported: {module_names}")
402
403 for module_name in PUBLIC_ALIASED_MODULES:
404 try:
405 eval(module_name)
406 except AttributeError:
407 module_names.append(module_name)
408
409 if module_names:
410 raise AssertionError("Modules in the public API that were not "
411 f"found: {module_names}")
412
413 with warnings.catch_warnings(record=True) as w:
414 warnings.filterwarnings('always', category=DeprecationWarning)
415 warnings.filterwarnings('always', category=ImportWarning)
416 for module_name in PRIVATE_BUT_PRESENT_MODULES:
417 if not check_importable(module_name):
418 # Nasty hack to avoid new FreeBSD failures. This
419 # is only needed for NumPy 2.4.x, so go with it
420 if not module_name == 'numpy.distutils.msvccompiler':
421 module_names.append(module_name)
422
423 if module_names:
424 raise AssertionError("Modules that are not really public but looked "
425 "public and can not be imported: "
426 f"{module_names}")
427
428
429@pytest.mark.xfail(
430 sysconfig.get_config_var("Py_DEBUG") not in (None, 0, "0"),
431 reason=(
432 "NumPy possibly built with `USE_DEBUG=True ./tools/travis-test.sh`, "
433 "which does not expose the `array_api` entry point. "
434 "See https://github.com/numpy/numpy/pull/19800"
435 ),
436)
437def test_array_api_entry_point():
438 """
439 Entry point for Array API implementation can be found with importlib and
440 returns the main numpy namespace.
441 """
442 # For a development install that did not go through meson-python,
443 # the entrypoint will not have been installed. So ensure this test fails
444 # only if numpy is inside site-packages.
445 numpy_in_sitepackages = sysconfig.get_path('platlib') in np.__file__
446
447 eps = importlib.metadata.entry_points()
448 xp_eps = eps.select(group="array_api")
449 if len(xp_eps) == 0:
450 if numpy_in_sitepackages:
451 msg = "No entry points for 'array_api' found"
452 raise AssertionError(msg) from None
453 return
454
455 try:
456 ep = next(ep for ep in xp_eps if ep.name == "numpy")
457 except StopIteration:
458 if numpy_in_sitepackages:
459 msg = "'numpy' not in array_api entry points"
460 raise AssertionError(msg) from None
461 return
462
463 if ep.value == 'numpy.array_api':
464 # Looks like the entrypoint for the current numpy build isn't
465 # installed, but an older numpy is also installed and hence the
466 # entrypoint is pointing to the old (no longer existing) location.
467 # This isn't a problem except for when running tests with `spin` or an
468 # in-place build.
469 return
470
471 xp = ep.load()
472 msg = (
473 f"numpy entry point value '{ep.value}' "
474 "does not point to our Array API implementation"
475 )
476 assert xp is numpy, msg
477
478
479def test_main_namespace_all_dir_coherence():
480 """
481 Checks if `dir(np)` and `np.__all__` are consistent and return
482 the same content, excluding exceptions and private members.
483 """
484 def _remove_private_members(member_set):
485 return {m for m in member_set if not m.startswith('_')}
486
487 def _remove_exceptions(member_set):
488 return member_set.difference({
489 "bool" # included only in __dir__
490 })
491
492 all_members = _remove_private_members(np.__all__)
493 all_members = _remove_exceptions(all_members)
494
495 dir_members = _remove_private_members(np.__dir__())
496 dir_members = _remove_exceptions(dir_members)
497
498 assert all_members == dir_members, (
499 "Members that break symmetry: "
500 f"{all_members.symmetric_difference(dir_members)}"
501 )
502
503
504@pytest.mark.filterwarnings(
505 r"ignore:numpy.core(\.\w+)? is deprecated:DeprecationWarning"
506)
507def test_core_shims_coherence():
508 """
509 Check that all "semi-public" members of `numpy._core` are also accessible
510 from `numpy.core` shims.
511 """
512 import numpy.core as core
513
514 for member_name in dir(np._core):
515 # Skip private and test members. Also if a module is aliased,
516 # no need to add it to np.core
517 if (
518 member_name.startswith("_")
519 or member_name in ["tests", "strings"]
520 or f"numpy.{member_name}" in PUBLIC_ALIASED_MODULES
521 ):
522 continue
523
524 member = getattr(np._core, member_name)
525
526 # np.core is a shim and all submodules of np.core are shims
527 # but we should be able to import everything in those shims
528 # that are available in the "real" modules in np._core, with
529 # the exception of the namespace packages (__spec__.origin is None),
530 # like numpy._core.include, or numpy._core.lib.pkgconfig.
531 if (
532 inspect.ismodule(member)
533 and member.__spec__ and member.__spec__.origin is not None
534 ):
535 submodule = member
536 submodule_name = member_name
537 for submodule_member_name in dir(submodule):
538 # ignore dunder names
539 if submodule_member_name.startswith("__"):
540 continue
541 submodule_member = getattr(submodule, submodule_member_name)
542
543 core_submodule = __import__(
544 f"numpy.core.{submodule_name}",
545 fromlist=[submodule_member_name]
546 )
547
548 assert submodule_member is getattr(
549 core_submodule, submodule_member_name
550 )
551
552 else:
553 assert member is getattr(core, member_name)
554
555
556def test_functions_single_location():
557 """
558 Check that each public function is available from one location only.
559
560 Test performs BFS search traversing NumPy's public API. It flags
561 any function-like object that is accessible from more that one place.
562 """
563 from collections.abc import Callable
564 from typing import Any
565
566 from numpy._core._multiarray_umath import (
567 _ArrayFunctionDispatcher as dispatched_function,
568 )
569
570 visited_modules: set[types.ModuleType] = {np}
571 visited_functions: set[Callable[..., Any]] = set()
572 # Functions often have `__name__` overridden, therefore we need
573 # to keep track of locations where functions have been found.
574 functions_original_paths: dict[Callable[..., Any], str] = {}
575
576 # Here we aggregate functions with more than one location.
577 # It must be empty for the test to pass.
578 duplicated_functions: list[tuple] = []
579
580 modules_queue = [np]
581
582 while len(modules_queue) > 0:
583
584 module = modules_queue.pop()
585
586 for member_name in dir(module):
587 member = getattr(module, member_name)
588
589 # first check if we got a module
590 if (
591 inspect.ismodule(member) and # it's a module
592 "numpy" in member.__name__ and # inside NumPy
593 not member_name.startswith("_") and # not private
594 "numpy._core" not in member.__name__ and # outside _core
595 # not a legacy or testing module
596 member_name not in ["f2py", "ma", "testing", "tests"] and
597 member not in visited_modules # not visited yet
598 ):
599 modules_queue.append(member)
600 visited_modules.add(member)
601
602 # else check if we got a function-like object
603 elif (
604 inspect.isfunction(member) or
605 isinstance(member, (dispatched_function, np.ufunc))
606 ):
607 if member in visited_functions:
608
609 # skip main namespace functions with aliases
610 if (
611 member.__name__ in [
612 "absolute", # np.abs
613 "arccos", # np.acos
614 "arccosh", # np.acosh
615 "arcsin", # np.asin
616 "arcsinh", # np.asinh
617 "arctan", # np.atan
618 "arctan2", # np.atan2
619 "arctanh", # np.atanh
620 "left_shift", # np.bitwise_left_shift
621 "right_shift", # np.bitwise_right_shift
622 "conjugate", # np.conj
623 "invert", # np.bitwise_not & np.bitwise_invert
624 "remainder", # np.mod
625 "divide", # np.true_divide
626 "concatenate", # np.concat
627 "power", # np.pow
628 "transpose", # np.permute_dims
629 ] and
630 module.__name__ == "numpy"
631 ):
632 continue
633 # skip trimcoef from numpy.polynomial as it is
634 # duplicated by design.
635 if (
636 member.__name__ == "trimcoef" and
637 module.__name__.startswith("numpy.polynomial")
638 ):
639 continue
640
641 # skip ufuncs that are exported in np.strings as well
642 if member.__name__ in (
643 "add",
644 "equal",
645 "not_equal",
646 "greater",
647 "greater_equal",
648 "less",
649 "less_equal",
650 ) and module.__name__ == "numpy.strings":
651 continue
652
653 # numpy.char reexports all numpy.strings functions for
654 # backwards-compatibility
655 if module.__name__ == "numpy.char":
656 continue
657
658 # function is present in more than one location!
659 duplicated_functions.append(
660 (member.__name__,
661 module.__name__,
662 functions_original_paths[member])
663 )
664 else:
665 visited_functions.add(member)
666 functions_original_paths[member] = module.__name__
667
668 del visited_functions, visited_modules, functions_original_paths
669
670 assert len(duplicated_functions) == 0, duplicated_functions
671
672
673def test___module___attribute():
674 modules_queue = [np]
675 visited_modules = {np}
676 visited_functions = set()
677 incorrect_entries = []
678
679 while len(modules_queue) > 0:
680 module = modules_queue.pop()
681 for member_name in dir(module):
682 member = getattr(module, member_name)
683 # first check if we got a module
684 if (
685 inspect.ismodule(member) and # it's a module
686 "numpy" in member.__name__ and # inside NumPy
687 not member_name.startswith("_") and # not private
688 "numpy._core" not in member.__name__ and # outside _core
689 # not in a skip module list
690 member_name not in [
691 "char", "core", "f2py", "ma", "lapack_lite", "mrecords",
692 "testing", "tests", "polynomial", "typing", "mtrand",
693 "bit_generator",
694 ] and
695 member not in visited_modules # not visited yet
696 ):
697 modules_queue.append(member)
698 visited_modules.add(member)
699 elif (
700 not inspect.ismodule(member) and
701 hasattr(member, "__name__") and
702 not member.__name__.startswith("_") and
703 member.__module__ != module.__name__ and
704 member not in visited_functions
705 ):
706 # skip ufuncs that are exported in np.strings as well
707 if member.__name__ in (
708 "add", "equal", "not_equal", "greater", "greater_equal",
709 "less", "less_equal",
710 ) and module.__name__ == "numpy.strings":
711 continue
712
713 # recarray and record are exported in np and np.rec
714 if (
715 (member.__name__ == "recarray" and module.__name__ == "numpy") or
716 (member.__name__ == "record" and module.__name__ == "numpy.rec")
717 ):
718 continue
719
720 # ctypeslib exports ctypes c_long/c_longlong
721 if (
722 member.__name__ in ("c_long", "c_longlong") and
723 module.__name__ == "numpy.ctypeslib"
724 ):
725 continue
726
727 # skip cdef classes
728 if member.__name__ in (
729 "BitGenerator", "Generator", "MT19937", "PCG64", "PCG64DXSM",
730 "Philox", "RandomState", "SFC64", "SeedSequence",
731 ):
732 continue
733
734 incorrect_entries.append(
735 {
736 "Func": member.__name__,
737 "actual": member.__module__,
738 "expected": module.__name__,
739 }
740 )
741 visited_functions.add(member)
742
743 if incorrect_entries:
744 assert len(incorrect_entries) == 0, incorrect_entries
745
746
747def _check_correct_qualname_and_module(obj) -> bool:
748 qualname = obj.__qualname__
749 name = obj.__name__
750 module_name = obj.__module__
751 assert name == qualname.split(".")[-1]
752
753 module = sys.modules[module_name]
754 actual_obj = functools.reduce(getattr, qualname.split("."), module)
755 return (
756 actual_obj is obj or
757 # `obj` may be a bound method/property of `actual_obj`:
758 (
759 hasattr(actual_obj, "__get__") and hasattr(obj, "__self__") and
760 actual_obj.__module__ == obj.__module__ and
761 actual_obj.__qualname__ == qualname
762 )
763 )
764
765
766def test___qualname___and___module___attribute():
767 # NumPy messes with module and name/qualname attributes, but any object
768 # should be discoverable based on its module and qualname, so test that.
769 # We do this for anything with a name (ensuring qualname is also set).
770 modules_queue = [np]
771 visited_modules = {np}
772 visited_functions = set()
773 incorrect_entries = []
774
775 while len(modules_queue) > 0:
776 module = modules_queue.pop()
777 for member_name in dir(module):
778 member = getattr(module, member_name)
779 # first check if we got a module
780 if (
781 inspect.ismodule(member) and # it's a module
782 "numpy" in member.__name__ and # inside NumPy
783 not member_name.startswith("_") and # not private
784 member_name not in {"tests", "typing"} and # type names don't match
785 "numpy._core" not in member.__name__ and # outside _core
786 member not in visited_modules # not visited yet
787 ):
788 modules_queue.append(member)
789 visited_modules.add(member)
790 elif (
791 not inspect.ismodule(member) and
792 hasattr(member, "__name__") and
793 not member.__name__.startswith("_") and
794 not member_name.startswith("_") and
795 not _check_correct_qualname_and_module(member) and
796 member not in visited_functions
797 ):
798 incorrect_entries.append(
799 {
800 "found_at": f"{module.__name__}:{member_name}",
801 "advertises": f"{member.__module__}:{member.__qualname__}",
802 }
803 )
804 visited_functions.add(member)
805
806 if incorrect_entries:
807 assert len(incorrect_entries) == 0, incorrect_entries
808 