On Tue, Apr 17, 2018 at 6:20 PM, Steven D'Aprano <st...@pearwood.info> wrote:
> If there are tests which intentionally verify this behaviour, that > really hurts your position that the behaviour is an accident of > implementation. It sounds like the behaviour is intended and required. > It is nonetheless bizarre and unexpected behavior. >>> prefix = 'global' >>> [prefix+c for c in 'abc'] ['globala', 'globalb', 'globalc'] >>> def func(): ... prefix = 'local' ... print([prefix+c for c in 'abc']) >>> func() ['locala', 'localb', 'localc'] >>> class klass: ... prefix = 'classy' ... items = [prefix+c for c in 'abc'] >>> print(klass.items) ['globala', 'globalb', 'globalc'] In Python 2, that last one would produce 'classya' and friends, due to the "broken" comprehension scope.
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com