I saw the same behavior for eating current exception not only for comprehensions but for iterating over generator with yield's (both iterating code and generator was in Cython).
On Tue, Jun 16, 2015 at 6:53 PM, Stefan Behnel <stefan...@behnel.de> wrote: > Andrew Svetlov schrieb am 13.06.2015 um 08:30: >> I have an issue in aiohttp library: >> https://github.com/KeepSafe/aiohttp/issues/410 >> >> The source of problem is: when I execute the following code >> >> body = ', '.join("'{}': {!r}".format(k, v) for k, v in self.items()) >> >> in except block Cython clears exception. >> >> Changing from comprehension to regular iteration works well: >> >> lst = [] >> for k, v in self._items: >> lst.append("'{}': {!r}".format(k, v)) >> body = ', '.join(lst) >> >> In pyre Python both versions don't clear current exception. > > Thanks for the report, I can reproduce it with this code: > > ''' > def genexpr_in_except(x, result): > """ > >>> result = [] > >>> try: genexpr_in_except([1, 2, 3], result) > ... except ValueError: print("OK") > ... else: print("NOT RAISED!") > OK > >>> result > [2, 4, 6] > > >>> result = [] > >>> genexpr_in_except([], result) > >>> result > [] > """ > try: > if x: > raise ValueError() > except ValueError: > assert sys.exc_info()[0] is ValueError, 1 > result[:] = list(i*2 for i in x) > assert sys.exc_info()[0] is ValueError, 2 > raise > ''' > > The "raise" at the end actually works, but the second "assert" makes it fail. > > Stefan > > _______________________________________________ > cython-devel mailing list > cython-devel@python.org > https://mail.python.org/mailman/listinfo/cython-devel -- Thanks, Andrew Svetlov _______________________________________________ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel