01.06.22 16:59, Chris Angelico пише:
On Wed, 1 Jun 2022 at 23:55, Serhiy Storchaka <storch...@gmail.com> wrote:
The advantage is that you cannot accidentally turn a function into a
generator by adding "yield". If the result of the call is ignored (it is
expected to be None), this bug can live a long time. It is a common
issue: test containing yield always passes. Since 3.11 the unittest
module emits a warning if a test method returns not None, but it will
not solve all problems: the test can call helpers, and if they are
generators, the call is virtually no-op. This error can also occur in
non-test code.
That might be nice, but without a massive backward compatibility break
(or another keyword for non-generator functions), it can't happen. Is
there any advantage to being able to declare that it must be a
generator (as opposed to simply returning a generator object)?
The advantage is not in the ability to declare that it must be a
generator, but in the ability to declare that it must not be a generator
(and this should be the default).
Of course it is a massive backward compatibility break, and the
transition should be very slow and careful. First introduce a new
optional syntax for generator functions, after 4 or 5 years (when all
maintained Python versions support the new syntax) start to emit a quiet
warning for a generator function with old syntax, after few more years
make it more loud, and finally, after yet more years, an error. In
between, third-party linters can start complaining about old syntax,
first these warnings will be disable by default. It all will take 8-10
years or more. Or we can just break the world in Python 4.0 (but this is
not the plan).
_______________________________________________
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/RXYPZKGRHFXOHG45XZS64YBTEXV4Z7YL/
Code of Conduct: http://python.org/psf/codeofconduct/