Skip to content

[mypyc] Report an error for vec item types i8, u16, u32 and u64 - #22482

Closed
Jahongir-Qurbonov wants to merge 1 commit into
python:masterfrom
Jahongir-Qurbonov:mypyc-vec-unsupported-item-types
Closed

Jahongir-Qurbonov wants to merge 1 commit into
python:masterfrom
Jahongir-Qurbonov:mypyc-vec-unsupported-item-types

Conversation

@Jahongir-Qurbonov

Copy link
Copy Markdown
Contributor

librt.vecs has specialized vec types only for the native int types i64, i32, i16 and u8. The other native int types (i8, u16, u32 and u64, the first and last added recently in #22447 and #22384) passed type checking as vec item types, but mypyc crashed when compiling a vec construction:

from librt.vecs import vec
from mypy_extensions import u64

def f() -> int:
    v = vec[u64]()
    return len(v)
m.py:5: AssertionError: unsupported: vec[u64]
m.py:5: note: this is an internal mypyc error; please report a bug at https://github.com/mypyc/mypyc/issues

(raised from vec_create in mypyc/irbuild/vec.py). In interpreted code, vec[u64]() falls through to the generic vec path with the u64 class as the item type, so the vec can't hold any values: append(v, 5) raises TypeError: invalid item type.

Now check_vec_type_args() reports Invalid item type for "vec" for these types, like it already does for vec[int], so the error is reported by type checking instead of an internal error during compilation. The docs mention that they aren't supported yet.

Adding real support would need new specialized vec types in the C runtime (and a change to the librt.vecs C API), which seems like a separate, larger change that's better left for when it's wanted. If that's preferred instead, I'm happy to close this.

Tests: vec[i8], vec[u16], vec[u32], vec[u64], a nested vec[vec[u64]] and vec[u64 | None] in check-vec.test, and a new irbuild error case in irbuild-vec-t.test that also covers vec[u64]() in a function body.

librt.vecs has specialized vec types only for the native int types i64,
i32, i16 and u8. Using another native int type as a vec item type passed
type checking, but mypyc then crashed with an internal error
("AssertionError: unsupported: vec[u64]") when compiling a vec
construction. In interpreted code, vec[u64]() created a generic vec that
couldn't hold any values (append raised "TypeError: invalid item type").

Now "Invalid item type for vec" is reported for these types, like for
vec[int].
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@JukkaL

JukkaL commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

#22497 adds support for the new vec item types, so this won't be needed.

@JukkaL JukkaL closed this Nov 16, 2026
@Jahongir-Qurbonov
Jahongir-Qurbonov deleted the mypyc-vec-unsupported-item-types branch November 16, 2026 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants