Repository: numpy/numpy
File: numpy/_core/code_generators/genapi.py (Python)

Code before:
        if self.min_version is not None:
            define = self.min_version.add_guard(self.name, define)
        return define

    def array_api_define(self):
        return f"        (void *) {self.name}"

    def internal_define(self):
        annstr = [str(a) for a in self.annotations]
        annstr = ' '.join(annstr)
        astr = f"""NPY_NO_EXPORT {annstr} {self.return_type} {self.name} \\
       ({self._argtypes_string()});"""
        return astr

def order_dict(d):
    """Order dict by its values."""
    o = list(d.items())

    def _key(x):
        return x[1] + (x[0],)
    return sorted(o, key=_key)

def merge_api_dicts(dicts):
    ret = {}
    for d in dicts:
        ret.update(dict(d.items()))

    return ret

def check_api_dict(d):
    """Check that an api dict is valid (does not use the same index twice)
    and removed `__unused_indices__` from it (which is important only here)
    """
    # Pop the `__unused_indices__` field:  These are known holes:
    removed = set(d.pop("__unused_indices__", []))
    # remove the extra value fields that aren't the index
    index_d = {k: v[0] for k, v in d.items()}

    # We have if a same index is used twice: we 'revert' the dict so that index
    # become keys. If the length is different, it means one index has been used
    # at least twice
    revert_dict = {v: k for k, v in index_d.items()}
    if not len(revert_dict) == len(index_d):
        # We compute a dict index -> list of associated items
        doubled = {}
        for name, index in index_d.items():
            try:
                doubled[index].append(name)
            except KeyError:
                doubled[index] = [name]
        fmt = "Same index has been used twice in api definition: {}"

Review comment (suggestion):
```pycon
>>> class dikt:
...     def keys(self):
...         yield 42
...     def __getitem__(self, key, /):
...         if key == 42:
...             return True
...         raise KeyError(key)
...         
>>> d = {}
>>> d.update(dikt())
>>> d
{42: True}
```

so it's probably safe enough to just

```suggestion
        ret.update(d)
```

Code after:
        if self.min_version is not None:
            define = self.min_version.add_guard(self.name, define)
        return define

    def array_api_define(self):
        return f"        (void *) {self.name}"

    def internal_define(self):
        annstr = [str(a) for a in self.annotations]
        annstr = ' '.join(annstr)
        astr = f"""NPY_NO_EXPORT {annstr} {self.return_type} {self.name} \\
       ({self._argtypes_string()});"""
        return astr

def order_dict(d):
    """Order dict by its values."""
    o = list(d.items())

    def _key(x):
        return x[1] + (x[0],)
    return sorted(o, key=_key)

def merge_api_dicts(dicts):
    ret = {}
    for d in dicts:
        ret.update(d)

    return ret

def check_api_dict(d):
    """Check that an api dict is valid (does not use the same index twice)
    and removed `__unused_indices__` from it (which is important only here)
    """
    # Pop the `__unused_indices__` field:  These are known holes:
    removed = set(d.pop("__unused_indices__", []))
    # remove the extra value fields that aren't the index
    index_d = {k: v[0] for k, v in d.items()}

    # We have if a same index is used twice: we 'revert' the dict so that index
    # become keys. If the length is different, it means one index has been used
    # at least twice
    revert_dict = {v: k for k, v in index_d.items()}
    if not len(revert_dict) == len(index_d):
        # We compute a dict index -> list of associated items
        doubled = {}
        for name, index in index_d.items():
            try:
                doubled[index].append(name)
            except KeyError:
                doubled[index] = [name]
        fmt = "Same index has been used twice in api definition: {}"