You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

`reveal_type`输出中星号的含义及`int`与`int*`的区别

Understanding the Asterisk in reveal_type Output & int vs int*

Hey there! Let's break down what that asterisk means in mypy's reveal_type output, and clarify the difference between int and int* in your code examples.

What the Asterisk Signifies

In mypy, that trailing * in the revealed type is a marker for modifiable l-values. Put simply, it means the expression points to a memory location you can overwrite later. Mypy uses this to signal that the type here isn't "fixed" at compile time—you could change the value's type in subsequent code, so mypy treats it with more flexibility and gives you a heads-up about this dynamic nature.

Breaking Down the Code Examples

Let's walk through each case to see how int and int* differ:

  • reveal_type(1) → builtins.int:
    The literal 1 is an immutable r-value—once created, it can't be changed. Its type is completely static and guaranteed to be int, so there's no asterisk needed here.

  • reveal_type(bla[0]) → builtins.int*:
    bla[0] refers to the first element in your list, which is a modifiable position. You could easily write something like bla[0] = "suddenly a string" later to change its type entirely. Mypy recognizes this mutability and adds the * to warn you that this value's type isn't guaranteed to stay int at runtime.

  • reveal_type(bla[0] * 2) → builtins.int:
    This is the result of multiplying bla[0] by 2—this creates a brand-new, immutable integer value. Even if bla[0] gets modified later, this calculation's result is a fixed int that can't be altered, so no asterisk is present.

内容的提问来源于stack exchange,提问作者Nova

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:58:15