Hello, On Tue, 19 Jan 2021 08:54:33 +0900 Inada Naoki <songofaca...@gmail.com> wrote:
> Hi, all. > > I want to write type hints without worrying about runtime overhead. > Current best practice is: > > ``` > from __future__ import annotations > > import typing > > if typing.TYPE_CHECKING: > import xxx # modules used only in type hints. > ``` > > But it would be nice if I can avoid importing even "typing" module. > How about adding TYPE_CHECKING builtin that is False? How about adding "very core", builtin, implemented in C, module for "language services"? It would have this var, get_annotations(), as language-level elaboration of typing.get_type_hints(), some core annotations (e.g. "const"), etc. Candidate names for such a module would be "lang", "python", or "__present__". Again, this module would deal with *language* level matters. That would differentiate it clearly from "sys", which largely deals with *implementation* level matters. E.g. sys.settrace() - whether tracing is implemented, and details of it, is implementation-specific matter; sys.intern() - whether interning is implemented, and details of it, is implementation-specific matter. Etc. Hmm, thinking about it, "is type checking is running currently" is also an implementation-specific matter (e.g., some implementations will run type checking always). So, sys.type_checking would be a place for that variable, sys being the builtin module, importing "instantly". (But that doesn't reduce need for language-level services module.) [] -- Best regards, Paul mailto:pmis...@gmail.com _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/BMQHLOMDZ2YFVI7TGSA2I4GZ7PCMQW56/ Code of Conduct: http://python.org/psf/codeofconduct/