This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author dpinol
Recipients dpinol
Date 2020-11-16.19:50:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1605556237.18.0.0550967152781.issue42377@roundup.psfhosted.org>
In-reply-to
Content
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).
History
Date User Action Args
2020-11-16 19:50:37dpinolsetrecipients: + dpinol
2020-11-16 19:50:37dpinolsetmessageid: <1605556237.18.0.0550967152781.issue42377@roundup.psfhosted.org>
2020-11-16 19:50:37dpinollinkissue42377 messages
2020-11-16 19:50:37dpinolcreate