On Sun, Feb 14, 2021 at 7:17 PM Inada Naoki <songofacandy@gmail.com> wrote:
On Mon, Feb 15, 2021 at 10:20 AM Joseph Perez <joperez@hotmail.fr> wrote:
>
> > How about having a pseudo-module called __typing__ that is
> > ignored by the compiler:
> >
> > from __typing__ import ...
> >
> > would be compiled to a no-op, but recognised by type checkers.
>
> If you want to do run-time typing stuff, you would use
> There is already a way of doing that: `if typing.TYPE_CHECKING: ...` https://docs.python.org/3/library/typing.html#typing.TYPE_CHECKING
> But yes, the issue with it is that this constant is defined in the `typing` module …
>
> However, I think this is a part of the solution. Indeed, the language could define another builtin constants, let's name it `__static__`, which would simply be always false (at runtime), while linters/type checkers would use it the same way `typing.TYPE_CHECKING` is used:
> ```python
> if __static__:
>     import typing
>     import expensive_module
> ```


Please note that this is a thread about PEP 649.

If PEP 649 accepted and PEP 563 dies, all such idioms breaks
annotation completely.

Users need to import all heavy modules and circular references used
only type hints, or user can not get even string form annotation which
is very useful for REPLs.

Hm, that's a rather serious problem with Larry's PEP 649 compared to `from __future__ import annotations`, actually.

Larry, what do you think?

--
--Guido van Rossum (python.org/~guido)