On 1/18/21 12:24 PM, Guido van Rossum wrote:
On Sun, Jan 17, 2021 at 7:33 AM Larry Hastings <la...@hastings.org
<mailto:la...@hastings.org>> wrote:
If your imports are complicated, you could always hide them in a
function. I just tried this and it seems to work fine:
def my_imports():
global other_mod
import other_mod
So, you could put all your imports in such a function, run it from
inside a "if typing.TYPE_CHECKING" block, and you'd have a
convenient way of doing all your imports from inside IPython too.
But static type checkers won't understand such imports. (Or is this
about annotations used for other purposes? Then I suppose it's fine,
but only as long as you completely give up static type checks for
modules that use this idiom.)
Oh, okay. I haven't used the static type checkers, so it's not clear to
me what powers they do and don't have. It was only a minor suggestion
anyway. Perhaps PEP 649 will be slightly inconvenient to people
exploring their code inside IPython.
Or maybe it'd work if they gated the if statement on running in ipython?
if typing.TYPE_CHECKING or os.path.split(sys.argv[0])[1] == "ipython3":
import other_mod
Cheers,
//arry/
_______________________________________________
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/DMD2LIV6LRVTVOPXKS4BWCLVQTH2NB3O/
Code of Conduct: http://python.org/psf/codeofconduct/