# Clarify \`Final\` assignment

**URL:** <https://discuss.python.org/t/clarify-final-assignment/106878>\
**Category:** Typing\
**Created:** [April 7, 2026, 1:11am UTC](https://discuss.python.org/t/clarify-final-assignment/106878 "2026-04-07T01:11:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![KotlinIsland](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/kotlinisland/32/19433_2.png) [@KotlinIsland](https://discuss.python.org/u/KotlinIsland)\
**Post date:** [April 7, 2026, 1:11am UTC](https://discuss.python.org/t/clarify-final-assignment/106878/1 "2026-04-07T01:11:34Z")

</div>

from [Final semantics](https://typing.python.org/en/latest/spec/qualifiers.html#semantics-and-examples):

> - There must be _exactly one_ assignment to a final name.

this leads to the following contradiction:  
Code sample in [basedpyright playground](https://basedpyright.com/?typeCheckingMode=all&reportUnannotatedClassAttribute=false&code=GYJw9gtgBALgngBwJYDsDmUkQWEMoBiqAhgDYBQ5AJgKbBQjEpWQD6AxmKq8KUggAoAlFAC0APigAjMGFIAuclGUMaMAK4gUUACoh1NZQGIoCEDVGds6mDSpR1AZ1QZiqslE6pKxeYRKkUAC8UACMmPSMzGxeKDx8giI0pI6GAAzGUABuZEhUADRQbs7opIbEjs5oKBA0KDCUUn5EKGSUSJFMLBAcXHG8-MKKKtLBYeTJqcMqUmMZUCaoOXwFRVCpnMzEIHBFlUjVtfVAA)

```python
from typing import Final

def random_coin_flip() -> bool:
    return True # pre-computed using a real coin

a: Final = 1 if random_coin_flip() else 0 # valid, a single assignment

b: Final[int] # the type could potentially be inferred here, but lets not say that it is mandatory to support

if random_coin_flip():
    b = 1
else:
    b = 0 # invalid, a secondary assignment

```

we can see that the semantics of `a` and `b` are identical, yet we observe different type checking behaviour

i don’t think that `b` should have this error

> <https://github.com/python/typing/pull/2241>
>
> https://discuss.python.org/t/clarify-final-assignment/106878

---

<div class="post-metadata">

**Author:** ![Jelle](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jelle/32/1049_2.png) [@Jelle](https://discuss.python.org/u/Jelle)\
**Post date:** [April 7, 2026, 2:04am UTC](https://discuss.python.org/t/clarify-final-assignment/106878/2 "2026-04-07T02:04:04Z")

</div>

Do we even need to support module-scope Final without an initializer?

```python
from typing import Final

A: Final
A = 1

```

Currently only pyright and ty allow this; mypy, zuban, pyrefly, and pycroscope reject it saying that a Final variable needs an initializer.

I know the spec explicitly allows Final instance attributes to be declared in class scope without an initializer, but that seems different and more useful.

---

<div class="post-metadata">

**Author:** ![mikeshardmind](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/mikeshardmind/32/14381_2.png) [@mikeshardmind](https://discuss.python.org/u/mikeshardmind)\
**Post date:** [April 7, 2026, 2:27am UTC](https://discuss.python.org/t/clarify-final-assignment/106878/3 "2026-04-07T02:27:53Z")

</div>

> [@Jelle](#):
>
> Do we even need to support module-scope Final without an initializer?

It’s useful when importing backports or optional accelerators to have constants defined based on which actual backend for _something_ is in use.

I’m in favor of the change, but I’m not sure the wording is as precise as it could be.

This is not the only place with typing where taking into account actual code flow would improve specified behavior. I think the proposed wording and specification change is fine for now, but there’s significantly more that could be improved in the same vein which might later result in wanting more precise language.

---

<div class="post-metadata">

**Author:** ![carljm](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/carljm/32/959_2.png) [@carljm](https://discuss.python.org/u/carljm)\
**Post date:** [April 7, 2026, 5:21am UTC](https://discuss.python.org/t/clarify-final-assignment/106878/4 "2026-04-07T05:21:14Z")

</div>

The same branchy-initialization case that the spec change aims to allow, effectively requires an initializer-less Final declaration; otherwise it would run afoul of “only one Final declaration allowed”.

---

<div class="post-metadata">

**Author:** ![JamesParrott](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jamesparrott/32/10534_2.png) [@JamesParrott](https://discuss.python.org/u/JamesParrott)\
**Post date:** [April 7, 2026, 9:20am UTC](https://discuss.python.org/t/clarify-final-assignment/106878/5 "2026-04-07T09:20:57Z")

</div>

It would indeed be very useful, as quite often I do things like:

```python
if random_coin_flip():
    b = 1
    # Some extra stuff
else:
    b = 0
    # Some other extra stuff

```

But using `Final` in an assignment-less declaration isn’t to my taste, personally.
