I don't work on these sorts of codebases, and I don't use type hints or
static type checking. So I'm not really qualified to judge how bad /
widespread a problem this is. It's my hope that the greater Python core
dev / user community can ascertain how serious this is.
My main observation is that, for users facing this problem, they still
have options. Off the top of my head, they could:
* maintain a lightweight "mock" version of expensive_module, or
* stringize their type hints by hand, or
* perhaps use with some hypothetical stringizing support library that
makes it less-painful to maintain stringized annotations.
(I assume that static type checkers could continue to support stringized
type hints even if PEP 649 was accepted.)
I admit I'd be very surprised if PEP 649 was judged to be unworkable,
given how similar it is to stock Python semantics for annotations at
runtime.
Cheers,
//arry/
On 2/15/21 8:14 PM, Guido van Rossum wrote:
On Sun, Feb 14, 2021 at 7:17 PM Inada Naoki <songofaca...@gmail.com
<mailto:songofaca...@gmail.com>> wrote:
On Mon, Feb 15, 2021 at 10:20 AM Joseph Perez <jope...@hotmail.fr
<mailto:jope...@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
<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 <http://python.org/~guido>)
/Pronouns: he/him //(why is my pronoun here?)/
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/FLMZYC2USYBTJABAQLVCNQEZUVVU26WD/
Code of Conduct: http://python.org/psf/codeofconduct/