3 ms·
The PEP appears to contradict itself about implementing the with statement using macros. > It is possible to demonstrate potential language extensions using ma
by ptx 6y ago
The PEP appears to contradict itself about implementing the with statement using macros.
> It is possible to demonstrate potential language extensions using macros. For example, macros would have enabled the with statement and yield from expression to have been trialed.
But later, in the example showing an implementation of the with statement:
> The above would require handling open specially.
If the macro-based with statement implementation can only handle the built-in open function and not arbitrary context managers, it's much more limited and not really the same feature. Does this mean that macros as proposed here cannot actually be used to implement something like the with statement?
Also:
> Annotations, either decorators or PEP 3107 function annotations, have a runtime cost even if they serve only as markers for checkers or as documentation.
But this runtime cost, if the decorator returns the original function, is essentially the cost of a function call when the module is loaded. If the decorator doesn't put a wrapper around the original function, there is no runtime cost when the function is called, only when it's defined. You would need a huge number of decorated functions for this to have a a detectable effect on module loading performance, I'd expect.