Message381147
Executing the following code we get this error on the "cast" call
NameError: name 'A' is not defined
```
from __future__ import annotations
from typing import TYPE_CHECKING, Optional, cast
if TYPE_CHECKING:
class A:
pass
def f(a: A):
pass
f(cast(A, "anything"))
```
It would be nice that you could use "cast" to force casts when the symbol is only available during TYPE_CHECKING. According to the "cast" specs, cast only works during type checking, but not during runtime. Hence, I think would be desirable that this code was legal. thanks
This returns the value unchanged. To the type checker this signals that the return value has the designated type, but at runtime we intentionally don’t check anything (we want this to be as fast as possible). |
|
Date |
User |
Action |
Args |
2020-11-16 19:50:37 | dpinol | set | recipients:
+ dpinol |
2020-11-16 19:50:37 | dpinol | set | messageid: <1605556237.18.0.0550967152781.issue42377@roundup.psfhosted.org> |
2020-11-16 19:50:37 | dpinol | link | issue42377 messages |
2020-11-16 19:50:37 | dpinol | create | |
|