Repository: numpy/numpy
File: numpy/_core/_type_aliases.py (Python)

Code before:
_extra_aliases = {
    "float": "float64",
    "complex": "complex128",
    "object": "object_",
    "bytes": "bytes_",
    "a": "bytes_",
    "int": "int_",
    "str": "str_",
    "unicode": "str_",
}

for k, v in _extra_aliases.items():
    sctypeDict[k] = allTypes[v]

# include extended precision sized aliases
for is_complex, full_name in [(False, "longdouble"), (True, "clongdouble")]:
    longdouble_type: type = allTypes[full_name]

    bits: int = dtype(longdouble_type).itemsize * 8
    base_name: str = "complex" if is_complex else "float"
    extended_prec_name: str = f"{base_name}{bits}"
    if extended_prec_name not in allTypes:
        sctypeDict[extended_prec_name] = longdouble_type
        allTypes[extended_prec_name] = longdouble_type


####################
# Building `sctypes`
####################

sctypes = {"int": set(), "uint": set(), "float": set(),
           "complex": set(), "others": set()}

for type_info in typeinfo.values():
    if type_info.kind in ["M", "m"]:  # exclude timedelta and datetime
        continue

    concrete_type = type_info.type

    # find proper group for each concrete type
    for type_group, abstract_type in [
        ("int", ma.signedinteger), ("uint", ma.unsignedinteger),
        ("float", ma.floating), ("complex", ma.complexfloating),
        ("others", ma.generic)
    ]:
        if issubclass(concrete_type, abstract_type):
            sctypes[type_group].add(concrete_type)
            break

# sort sctype groups by bitsize
for sctype_key in sctypes.keys():

Review comment (suggestion):
This probably looks very out of character, but on Python >=3.14 these were causing a module-level `__conditional_annotations__` name to be generated (no mention of this anywhere in the python docs, but it's a `set` of integer indices 🤷🏻). That was causing stubtest to report the following error:

```
numpy._core._type_aliases.__conditional_annotations__ is not present in stub
```

So it was indirectly also causing namespace pollution in that sense.

Usually I tend to ignore these kinds of stubtest errors, but in this case that'd be pretty annoying, seeing as it depends on the Python version. Ignoring errors in stubtest involves an "allowlist", and stubtest will also report an error for "unused allowlist entries". So to ignore this, we'd have to write a wrapper script that would conditionally select the allowlist, depending on the Python version used, and call stubtest with that.

And since these annotations were redundant anyways (type-checkers can infer those types themselves just fine), I thought we might as well get rid of them.

Code after:
    del k, v

# extra aliases are added only to `sctypeDict`
# to support dtype name access, such as`np.dtype("float")`
_extra_aliases = {
    "float": "float64",
    "complex": "complex128",
    "object": "object_",
    "bytes": "bytes_",
    "a": "bytes_",
    "int": "int_",
    "str": "str_",
    "unicode": "str_",
}

for k, v in _extra_aliases.items():
    sctypeDict[k] = allTypes[v]
    del k, v

# include extended precision sized aliases
for is_complex, full_name in [(False, "longdouble"), (True, "clongdouble")]:
    longdouble_type = allTypes[full_name]

    bits = dtype(longdouble_type).itemsize * 8
    base_name = "complex" if is_complex else "float"
    extended_prec_name = f"{base_name}{bits}"
    if extended_prec_name not in allTypes:
        sctypeDict[extended_prec_name] = longdouble_type
        allTypes[extended_prec_name] = longdouble_type

    del is_complex, full_name, longdouble_type, bits, base_name, extended_prec_name


####################
# Building `sctypes`
####################

sctypes = {"int": set(), "uint": set(), "float": set(),
           "complex": set(), "others": set()}

for type_info in typeinfo.values():
    if type_info.kind in ["M", "m"]:  # exclude timedelta and datetime
        continue

    concrete_type = type_info.type

    # find proper group for each concrete type
    for type_group, abstract_type in [
        ("int", ma.signedinteger), ("uint", ma.unsignedinteger),
        ("float", ma.floating), ("complex", ma.complexfloating),
        ("others", ma.generic)