New submission from Daniel Pinyol <git...@dpinol.com>:

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).

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42377>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to