2017-09-13 13:01 GMT-07:00 Jim J. Jewett
On Wed, Sep 13, 2017 at 3:12 PM, Lukasz Langa
wrote: On Sep 13, 2017, at 2:56 PM, Jim J. Jewett
wrote: I am generally supportive of leaving the type annotations unprocessed by default, but there are use cases where they should be processed (and even cases where doing it at the right time matters, because of a side effect).
What is the "right time" you're speaking of?
The "right time" is whenever they are currently evaluated. (Definition time, I think, but won't swear.)
For example, the "annotation" might really be a call to a logger, showing the current environment, including names that will be rebound before the module finishes loading.
I'm perfectly willing to agree that even needing this much control over timing is a code smell, but it is currently possible, and I would rather it not become impossible.
Is this just a theoretical concern? Unless there is significant real-world code doing this sort of thing, I don't see much of a problem in deprecating such code using the normal __future__-based deprecation cycle.
At a minimum, it seems like "just run this typing function that you should already be using" should either save the right context, or the PEP should state explicitly that this functionality is being withdrawn. (And go ahead and suggest a workaround, such as running the code before the method definition, or as a decorator.)
(1) The PEP suggests opting out with @typing.no_type_hints ...
This is already possible. PEP 484 specifies that
"A # type: ignore comment on a line by itself is equivalent to adding an inline # type: ignore to each line until the end of the current indented block. At top indentation level this has effect of disabling type checking until the end of file."
Great! Please mention this as well as (or perhaps instead of) typing.no_type_check.
It would be a bit messy (like the old coding cookie), but recognizing a module-wide
# typing.no_type_hints
comment and then falling back to the current behavior would be enough for me.
Do you know of any other per-module feature toggle of this kind?
No, thus the comment about it being messy. But it does offer one way to ensure that annotations are evaluated within the proper environment, even without having to save those environments.
-jJ _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/