From 66f7db589498b4af2c86b8f9d4cb443915142b67 Mon Sep 17 00:00:00 2001 From: cfbolz Date: Thu, 20 Sep 2007 17:17:22 +0200 Subject: [PATCH] [svn r46770] add py.builtin.GeneratorExit, to make it possible to write 2.3 and 2.4 compatible code. The exception is never raised there. --HG-- branch : trunk --- py/__init__.py | 6 ++++-- py/builtin/exception.py | 9 +++++++++ py/builtin/testing/test_exception.py | 5 +++++ py/test/rsession/master.py | 1 + 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/py/__init__.py b/py/__init__.py index 1791a893f..786919ff4 100644 --- a/py/__init__.py +++ b/py/__init__.py @@ -11,8 +11,8 @@ version = "0.9.1-alpha" initpkg(__name__, description = "pylib and py.test: agile development and test support library", - revision = int('$LastChangedRevision: 45649 $'.split(':')[1][:-1]), - lastchangedate = '$LastChangedDate: 2007-08-14 11:49:04 +0200 (Tue, 14 Aug 2007) $', + revision = int('$LastChangedRevision: 46770 $'.split(':')[1][:-1]), + lastchangedate = '$LastChangedDate: 2007-09-20 17:17:22 +0200 (Thu, 20 Sep 2007) $', version = version, url = "http://codespeak.net/py", download_url = "XXX", # "http://codespeak.net/download/py/py-%s.tar.gz" %(version,), @@ -33,6 +33,7 @@ initpkg(__name__, 'test.exit' : ('./test/session.py', 'exit'), 'test.broken' : ('./test/item.py', 'Broken'), 'test.notimplemented' : ('./test/item.py', '_NotImplemented'), + 'test._pdb' : ('./test/custompdb.py', 'set_trace'), # configuration/initialization related test api 'test.config' : ('./test/config.py', 'config_per_process'), @@ -92,6 +93,7 @@ initpkg(__name__, 'builtin.reversed' : ('./builtin/reversed.py', 'reversed'), 'builtin.sorted' : ('./builtin/sorted.py', 'sorted'), 'builtin.BaseException' : ('./builtin/exception.py', 'BaseException'), + 'builtin.GeneratorExit' : ('./builtin/exception.py', 'GeneratorExit'), 'builtin.set' : ('./builtin/set.py', 'set'), 'builtin.frozenset' : ('./builtin/set.py', 'frozenset'), diff --git a/py/builtin/exception.py b/py/builtin/exception.py index 35a80a102..204646e2a 100644 --- a/py/builtin/exception.py +++ b/py/builtin/exception.py @@ -2,3 +2,12 @@ try: BaseException = BaseException except NameError: BaseException = Exception + +try: + GeneratorExit = GeneratorExit +except NameError: + class GeneratorExit(Exception): + """ This exception is never raised, it is there to make it possible to + write code compatible with CPython 2.5 even in lower CPython + versions.""" + pass diff --git a/py/builtin/testing/test_exception.py b/py/builtin/testing/test_exception.py index 5fa08a943..c02f1acce 100644 --- a/py/builtin/testing/test_exception.py +++ b/py/builtin/testing/test_exception.py @@ -11,3 +11,8 @@ def test_BaseException(): assert py.builtin.BaseException.__module__ == 'exceptions' assert Exception.__name__ == 'Exception' + + +def test_GeneratorExit(): + assert py.builtin.GeneratorExit.__module__ == 'exceptions' + assert issubclass(py.builtin.GeneratorExit, Exception) diff --git a/py/test/rsession/master.py b/py/test/rsession/master.py index 0c20b79df..d497002b1 100644 --- a/py/test/rsession/master.py +++ b/py/test/rsession/master.py @@ -5,6 +5,7 @@ import py from py.__.test.outcome import ReprOutcome from py.__.test import repevent from py.__.test.outcome import Skipped +from py.builtin import GeneratorExit class MasterNode(object): def __init__(self, channel, reporter):