[docs] [issue33477] Document that compile(code, 'exec') has different behavior in 3.7+
report at bugs.python.org
Fri May 18 13:02:04 EDT 2018
Matthias Bussonnier <bussonniermatthias at gmail.com> added the comment:
Fair enough that what's new include things about Module
> The first statement in their body is not considered as a docstring anymore.
Note that this sentence read backward to me. I understand what is meant because I know the new behavior. It might be good to clarify. potentially:
> The first statement in the `body` attribute of should not be considered the docstring of the module anymore, the `docstring` attribute is reserved for that.
Though the documentation of `compile()` does not say that `compile(...,'exec')` compile a module. It says:
> The mode argument specifies what kind of code must be compiled;
> it can be 'exec' if source consists of a sequence of statements
Which now is incorrect. I was expecting `compile(..., 'exec')` to return a Module with `None` or empty string as the docstring attribute – which is also a perfectly reasonable request.
I think that `compile` documentation should be changed to reflect what it does.
Or (but I see why this is un-reasonable) split add the `mode='module'` that has new behavior, while `exec` does not.
Python tracker <report at bugs.python.org>
More information about the docs