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

Function check_api_dict

numpy/core/code_generators/genapi.py:469–500  ·  view source on GitHub ↗

Check that an api dict is valid (does not use the same index twice).

(d)

Source from the content-addressed store, hash-verified

467 return ret
468
469def check_api_dict(d):
470 """Check that an api dict is valid (does not use the same index twice)."""
471 # remove the extra value fields that aren't the index
472 index_d = {k: v[0] for k, v in d.items()}
473
474 # We have if a same index is used twice: we 'revert' the dict so that index
475 # become keys. If the length is different, it means one index has been used
476 # at least twice
477 revert_dict = {v: k for k, v in index_d.items()}
478 if not len(revert_dict) == len(index_d):
479 # We compute a dict index -> list of associated items
480 doubled = {}
481 for name, index in index_d.items():
482 try:
483 doubled[index].append(name)
484 except KeyError:
485 doubled[index] = [name]
486 fmt = "Same index has been used twice in api definition: {}"
487 val = ''.join(
488 '\n\tindex {} -> {}'.format(index, names)
489 for index, names in doubled.items() if len(names) != 1
490 )
491 raise ValueError(fmt.format(val))
492
493 # No 'hole' in the indexes may be allowed, and it must starts at 0
494 indexes = set(index_d.values())
495 expected = set(range(len(indexes)))
496 if indexes != expected:
497 diff = expected.symmetric_difference(indexes)
498 msg = "There are some holes in the API indexing: " \
499 "(symmetric diff is %s)" % diff
500 raise ValueError(msg)
501
502def get_api_functions(tagname, api_dict):
503 """Parse source files to get functions tagged by the given tag."""

Callers

nothing calls this directly

Calls 2

valuesMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected