]> granicus.if.org Git - python/commitdiff
Merged revisions 63208-63209,63211-63212,63214-63217,63219-63224,63226-63227,63229...
authorAlexandre Vassalotti <alexandre@peadrop.com>
Fri, 16 May 2008 04:39:54 +0000 (04:39 +0000)
committerAlexandre Vassalotti <alexandre@peadrop.com>
Fri, 16 May 2008 04:39:54 +0000 (04:39 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r63208 | georg.brandl | 2008-05-13 15:04:54 -0400 (Tue, 13 May 2008) | 2 lines

  #2831: add start argument to enumerate(). Patch by Scott Dial and me.
........
  r63209 | marc-andre.lemburg | 2008-05-13 15:10:45 -0400 (Tue, 13 May 2008) | 3 lines

  Remove leftovers from reverted setuptools checkin (they were added in r45525).
........
  r63211 | georg.brandl | 2008-05-13 17:32:03 -0400 (Tue, 13 May 2008) | 2 lines

  Fix a refleak in the _warnings module.
........
  r63212 | andrew.kuchling | 2008-05-13 20:46:41 -0400 (Tue, 13 May 2008) | 1 line

  List all the removes and renamed modules
........
  r63214 | brett.cannon | 2008-05-13 21:09:40 -0400 (Tue, 13 May 2008) | 2 lines

  Rewrap some lines in test_py3kwarn.
........
  r63219 | georg.brandl | 2008-05-14 02:34:15 -0400 (Wed, 14 May 2008) | 2 lines

  Add NEWS entry for #2831.
........
  r63220 | neal.norwitz | 2008-05-14 02:47:56 -0400 (Wed, 14 May 2008) | 3 lines

  Fix "refleak" by restoring the tearDown method removed by accident (AFAICT)
  in r62788.
........
  r63221 | georg.brandl | 2008-05-14 03:18:22 -0400 (Wed, 14 May 2008) | 2 lines

  Fix another "refleak" by clearing the filters after test.
........
  r63222 | neal.norwitz | 2008-05-14 03:21:42 -0400 (Wed, 14 May 2008) | 5 lines

  Install the json package and tests as well as the lib2to3 tests
  so the tests work when run from an install directory.
  They are currently skipped on the daily runs (not from the buildbots)
  for checking refleaks, etc.
........
  r63256 | andrew.kuchling | 2008-05-14 21:10:24 -0400 (Wed, 14 May 2008) | 1 line

  Note some removals and a rename
........
  r63311 | brett.cannon | 2008-05-15 00:36:53 -0400 (Thu, 15 May 2008) | 2 lines

  Add a snippet for the deprecation directive for docs.
........
  r63313 | gregory.p.smith | 2008-05-15 00:56:18 -0400 (Thu, 15 May 2008) | 5 lines

  disable the crashing test.  I will also file a bug.  This crash does
  not appear to be a new bug, its just that the test coverage went up
  recently exposing it.  (I verified that by testing this test code on
  an older Modules/_bsddb.c)
........
  r63320 | georg.brandl | 2008-05-15 11:08:32 -0400 (Thu, 15 May 2008) | 2 lines

  #2863: add gen.__name__ and add this name to generator repr().
........
  r63324 | andrew.kuchling | 2008-05-15 16:07:39 -0400 (Thu, 15 May 2008) | 1 line

  Import class from distutils.cmd, not .core, to avoid circular import
........
  r63327 | alexandre.vassalotti | 2008-05-15 16:31:42 -0400 (Thu, 15 May 2008) | 2 lines

  Fixed typo in a doctest of test_genexps.
........
  r63332 | benjamin.peterson | 2008-05-15 18:34:33 -0400 (Thu, 15 May 2008) | 2 lines

  add Mac modules to the list of deprecated ones
........
  r63333 | benjamin.peterson | 2008-05-15 18:41:16 -0400 (Thu, 15 May 2008) | 2 lines

  fix typos in whatsnew
........
  r63348 | benjamin.peterson | 2008-05-15 22:24:49 -0400 (Thu, 15 May 2008) | 2 lines

  make test_platform a bit more assertive (We'll see what the buildbots say.)
........

18 files changed:
Doc/library/functions.rst
Doc/whatsnew/2.6.rst
Lib/bsddb/test/test_lock.py
Lib/distutils/config.py
Lib/test/test_enumerate.py
Lib/test/test_generators.py
Lib/test/test_genexps.py
Lib/test/test_platform.py
Lib/test/test_site.py
Lib/test/test_warnings.py
Makefile.pre.in
Misc/NEWS
Misc/TextMate/Python-Dev.tmbundle/Snippets/2 to 3 - Module Deletion (docs).tmSnippet [new file with mode: 0644]
Misc/TextMate/Python-Dev.tmbundle/info.plist
Objects/enumobject.c
Objects/genobject.c
Python/_warnings.c
Python/compile.c

index 582abbf609efd94d30b423c54443fba165963186..def6ae64c09d2a254f871a8849b0a40bb24d8565 100644 (file)
@@ -325,15 +325,15 @@ are always available.  They are listed here in alphabetical order.
    < abs(b)``.
 
 
-.. function:: enumerate(sequence)
+.. function:: enumerate(sequence[, start=0])
 
    Return an enumerate object. *sequence* must be a sequence, an
    :term:`iterator`, or some other object which supports iteration.  The
    :meth:`__next__` method of the iterator returned by :func:`enumerate` returns a
-   tuple containing a count (from zero) and the corresponding value obtained
-   from iterating over *iterable*.  :func:`enumerate` is useful for obtaining an
-   indexed series: ``(0, seq[0])``, ``(1, seq[1])``, ``(2, seq[2])``, .... For
-   example:
+   tuple containing a count (from *start* which defaults to 0) and the
+   corresponding value obtained from iterating over *iterable*.
+   :func:`enumerate` is useful for obtaining an indexed series: ``(0, seq[0])``,
+   ``(1, seq[1])``, ``(2, seq[2])``, .... For example:
 
       >>> for i, season in enumerate(['Spring', 'Summer', 'Fall', 'Winter')]:
       ...     print(i, season)
index c39c80ab65753989f82ea71909eac34e0934d0c6..31ea41d094177c099cdd45fe186c8ddd99ff5962 100644 (file)
@@ -1466,13 +1466,86 @@ New, Improved, and Deprecated Modules
 As usual, Python's standard library received a number of enhancements and bug
 fixes.  Here's a partial list of the most notable changes, sorted alphabetically
 by module name. Consult the :file:`Misc/NEWS` file in the source tree for a more
-complete list of changes, or look through the CVS logs for all the details.
-
-* (3.0-warning mode) The :mod:`audiodev` module is being deprecated,
-  and has been removed from Python 3.0, so importing it now triggers a
-  warning.  The module hasn't been maintained for several versions,
-  and is written against an outdated sound interface for SunOS and
-  IRIX.
+complete list of changes, or look through the Subversion logs for all the
+details.
+
+* (3.0-warning mode) Python 3.0 will feature a reorganized standard 
+  library; many outdated modules are being dropped,
+  and some modules are being renamed or moved into packages. 
+  Python 2.6 running in 3.0-warning mode will warn about these modules 
+  when they are imported.
+  The list of deprecated modules is:
+  :mod:`_builtinSuites`,
+  :mod:`aepack`,
+  :mod:`aetools`,
+  :mod:`aetypes`,
+  :mod:`applesingle`,
+  :mod:`appletrawmain`,
+  :mod:`appletrunner`,
+  :mod:`argvemulator`,
+  :mod:`Audio_mac`,
+  :mod:`audiodev`,
+  :mod:`autoGIL`,
+  :mod:`bgenlocations`,
+  :mod:`buildtools`,
+  :mod:`bundlebuilder`,
+  :mod:`Canvas`,
+  :mod:`Carbon`,
+  :mod:`cfmfile`,
+  :mod:`CodeWarrior`,
+  :mod:`ColorPicker`,
+  :mod:`compiler`,
+  :mod:`cd`,
+  :mod:`cddb`,
+  :mod:`cdplayer`,
+  :mod:`CL` and :mod:`cl`,
+  :mod:`cd`,
+  :mod:`cd`,
+  :mod:`dircache`,
+  :mod:`dl`,
+  :mod:`EasyDialogs`,
+  :mod:`Explorer`,
+  :mod:`Finder`,
+  :mod:`FrameWork`,
+  :mod:`findertools`,
+  :mod:`fpformat`,
+  :mod:`gensuitemodule`,
+  :mod:`ic`,
+  :mod:`icglue`,
+  :mod:`icopen`,
+  :mod:`ihooks`,
+  :mod:`imageop`,
+  :mod:`linuxaudiodev`,
+  :mod:`macerrors`,
+  :mod:`MacOS`,
+  :mod:`macostools`,
+  :mod:`macresource`,
+  :mod:`mhlib`,
+  :mod:`MiniAEFrame`,
+  :mod:`multifile`,
+  :mod:`Nav`,
+  :mod:`Netscape`,
+  :mod:`new`,
+  :mod:`OSATerminology`,
+  :mod:`pimp`,
+  :mod:`PixMapWrapper`,
+  :mod:`popen2`,
+  :mod:`pure`,
+  :mod:`StdSuites`,
+  :mod:`sv`,
+  :mod:`SystemEvents`,
+  :mod:`Terminal`,
+  :mod:`terminalcommand`,
+  :mod:`test.testall`,
+  :mod:`toaiff`,
+  :mod:`videoreader`.
+
+  The modules that have been renamed are:
+
+  * :mod:`ConfigParser` has become :mod:`configparser`.
+  * :mod:`copy_reg` has become :mod:`copyreg`.
+  * :mod:`SocketServer` has become :mod:`socketserver`.
+  * :mod:`Queue` has become :mod:`queue`.
 
 * The :mod:`bsddb.dbshelve` module now uses the highest pickling protocol
   available, instead of restricting itself to protocol 1.
@@ -1755,9 +1828,6 @@ complete list of changes, or look through the CVS logs for all the details.
   the forward search.
   (Contributed by John Lenton.)
 
-* (3.0-warning mode) The :mod:`new` module has been removed from
-  Python 3.0.  Importing it therefore triggers a warning message.
-
 * The :mod:`operator` module gained a 
   :func:`methodcaller` function that takes a name and an optional 
   set of arguments, returning a callable that will call 
index 973bc4286f616f8f316043865e47592ae2aedd5d..402d147b4bff68e829c77caf7cde29a3127f6400 100644 (file)
@@ -94,15 +94,55 @@ class LockingTestCase(unittest.TestCase):
         for t in threads:
             t.join()
 
-    def test03_set_timeout(self):
-        # test that the set_timeout call works
-        if hasattr(self.env, 'set_timeout'):
-            self.env.set_timeout(0, db.DB_SET_LOCK_TIMEOUT)
-            self.env.set_timeout(0, db.DB_SET_TXN_TIMEOUT)
-            self.env.set_timeout(123456, db.DB_SET_LOCK_TIMEOUT)
-            self.env.set_timeout(7890123, db.DB_SET_TXN_TIMEOUT)
-
-    def theThread(self, sleepTime, lockType):
+    def _DISABLED_test03_lock_timeout(self):
+        # Disabled as this test crashes the python interpreter built in
+        # debug mode with:
+        #  Fatal Python error: UNREF invalid object
+        # the error occurs as marked below.
+        self.env.set_timeout(0, db.DB_SET_LOCK_TIMEOUT)
+        self.env.set_timeout(0, db.DB_SET_TXN_TIMEOUT)
+        self.env.set_timeout(123456, db.DB_SET_LOCK_TIMEOUT)
+        self.env.set_timeout(7890123, db.DB_SET_TXN_TIMEOUT)
+
+        def deadlock_detection() :
+            while not deadlock_detection.end :
+                deadlock_detection.count = \
+                    self.env.lock_detect(db.DB_LOCK_EXPIRE)
+                if deadlock_detection.count :
+                    while not deadlock_detection.end :
+                        pass
+                    break
+                time.sleep(0.01)
+
+        deadlock_detection.end=False
+        deadlock_detection.count=0
+        t=Thread(target=deadlock_detection)
+        t.setDaemon(True)
+        t.start()
+        self.env.set_timeout(100000, db.DB_SET_LOCK_TIMEOUT)
+        anID = self.env.lock_id()
+        anID2 = self.env.lock_id()
+        self.assertNotEqual(anID, anID2)
+        lock = self.env.lock_get(anID, "shared lock", db.DB_LOCK_WRITE)
+        start_time=time.time()
+        # FIXME: I see the UNREF crash as the interpreter trys to exit
+        # from this call to lock_get.
+        self.assertRaises(db.DBLockNotGrantedError,
+                self.env.lock_get,anID2, "shared lock", db.DB_LOCK_READ)
+        end_time=time.time()
+        deadlock_detection.end=True
+        self.assertTrue((end_time-start_time) >= 0.1)
+        self.env.lock_put(lock)
+        t.join()
+
+        if db.version() >= (4,0):
+            self.env.lock_id_free(anID)
+            self.env.lock_id_free(anID2)
+
+        if db.version() >= (4,6):
+            self.assertTrue(deadlock_detection.count>0)
+
+    def theThread(self, lockType):
         name = currentThread().getName()
         if lockType ==  db.DB_LOCK_WRITE:
             lt = "write"
index a625aec5e6bf8919d30361c045532d65981c9c76..6ffccaa095690b046a5198aff238f9dbd9dd4198 100644 (file)
@@ -7,7 +7,7 @@ import os
 import sys
 from configparser import ConfigParser
 
-from distutils.core import Command
+from distutils.cmd import Command
 
 DEFAULT_PYPIRC = """\
 [pypirc]
index 08229bfa7863a9356499acf86e6799b1d383f2e7..8cebf444696d4809d095906a2e7e29569c6dc360 100644 (file)
@@ -100,7 +100,8 @@ class EnumerateTestCase(unittest.TestCase):
     def test_argumentcheck(self):
         self.assertRaises(TypeError, self.enum) # no arguments
         self.assertRaises(TypeError, self.enum, 1) # wrong type (not iterable)
-        self.assertRaises(TypeError, self.enum, 'abc', 2) # too many arguments
+        self.assertRaises(TypeError, self.enum, 'abc', 'a') # wrong type
+        self.assertRaises(TypeError, self.enum, 'abc', 2, 3) # too many arguments
 
     def test_tuple_reuse(self):
         # Tests an implementation detail where tuple is reused
@@ -196,6 +197,19 @@ class TestReversed(unittest.TestCase):
         self.assertEqual(rc, sys.getrefcount(r))
 
 
+class TestStart(EnumerateTestCase):
+
+    enum = lambda i: enumerate(i, start=11)
+    seq, res = 'abc', [(1, 'a'), (2, 'b'), (3, 'c')]
+
+
+class TestLongStart(EnumerateTestCase):
+
+    enum = lambda i: enumerate(i, start=sys.maxsize+1)
+    seq, res = 'abc', [(sys.maxsize+1,'a'), (sys.maxsize+2,'b'),
+                       (sys.maxsize+3,'c')]
+
+
 def test_main(verbose=None):
     testclasses = (EnumerateTestCase, SubclassTestCase, TestEmpty, TestBig,
                    TestReversed)
index 992126ff05d893ce95900a0ff01d49046951bb39..e27eaddaaeea5d1e3c0d1b07cccd668feceb1af1 100644 (file)
@@ -917,6 +917,17 @@ StopIteration
 >>> g.gi_code is f.__code__
 True
 
+
+Test the __name__ attribute and the repr()
+
+>>> def f():
+...    yield 5
+...
+>>> g = f()
+>>> g.__name__
+'f'
+>>> repr(g)  # doctest: +ELLIPSIS
+'<f generator object at ...>'
 """
 
 # conjoin is a simple backtracking generator, named in honor of Icon's
index 46f7ab88f35eed84fd32563b7ab2cddd7c586a0b..c8abbccb0c5e0378bb290af33624cadf1bcdaa1d 100644 (file)
@@ -92,7 +92,7 @@ Verify that parenthesis are required when used as a keyword argument value
 Verify that parenthesis are required when used as a keyword argument value
 
     >>> dict(a = (i for i in range(10))) #doctest: +ELLIPSIS
-    {'a': <generator object at ...>}
+    {'a': <<genexpr> generator object at ...>}
 
 Verify early binding for the outermost for-expression
 
index 22307cd65676e3a34cf0fabf33a4a59845302589..fced4d021529d4a68710ca9f99e5c903a8120303 100644 (file)
@@ -1,7 +1,9 @@
+import sys
 import unittest
-from test import test_support
 import platform
 
+from test import test_support
+
 class PlatformTest(unittest.TestCase):
     def test_architecture(self):
         res = platform.architecture()
@@ -49,26 +51,35 @@ class PlatformTest(unittest.TestCase):
 
     def test_uname(self):
         res = platform.uname()
+        self.assert_(any(res))
 
     def test_java_ver(self):
         res = platform.java_ver()
+        if sys.platform == 'java':
+            self.assert_(all(res))
 
     def test_win32_ver(self):
         res = platform.win32_ver()
 
     def test_mac_ver(self):
         res = platform.mac_ver()
+        try:
+            import gestalt
+        except ImportError: pass
+        else:
+            if sys.platform == 'darwin':
+                self.assert_(all(res))
 
     def test_dist(self):
         res = platform.dist()
 
     def test_libc_ver(self):
-        from sys import executable
         import os
-        if os.path.isdir(executable) and os.path.exists(executable+'.exe'):
+        if os.path.isdir(sys.executable) and \
+           os.path.exists(sys.executable+'.exe'):
             # Cygwin horror
             executable = executable + '.exe'
-        res = platform.libc_ver(executable)
+        res = platform.libc_ver(sys.executable)
 
 def test_main():
     test_support.run_unittest(
index 329df4b98a4ab37d9bb152a7e7438b42e0cbe994..a13751c56fe7de8b4c6bff26edcc1c9dd3b2c1fb 100644 (file)
@@ -36,7 +36,7 @@ class HelperFunctionsTests(unittest.TestCase):
         """Save a copy of sys.path"""
         self.sys_path = sys.path[:]
 
-
+    def tearDown(self):
         """Restore sys.path"""
         sys.path = self.sys_path
 
@@ -256,13 +256,8 @@ class ImportSideEffectTests(unittest.TestCase):
             else:
                 self.fail("sitecustomize not imported automatically")
 
-
-
-
 def test_main():
     run_unittest(HelperFunctionsTests, ImportSideEffectTests)
 
-
-
 if __name__ == "__main__":
     test_main()
index fa2297ce28e95342317455375e9b22bbe555f2d9..7b512ef3d664cd70ce852abebdc147a911e6412e 100644 (file)
@@ -396,6 +396,7 @@ class _WarningsTests(BaseTest):
             self.assertRaises(TypeError, self.module.warn, "Warning!")
         finally:
             self.module.showwarning = old_showwarning
+            self.module.resetwarnings()
 
     def test_show_warning_output(self):
         # With showarning() missing, make sure that output is okay.
index b82bd5e47b2c04709f590bbe75b60bdc434873e4..3b96df7cb9c76b7858132d9a72596709ff973b7f 100644 (file)
@@ -812,9 +812,10 @@ LIBSUBDIRS=        lib-tk site-packages test test/output test/data \
                test/decimaltestdata \
                encodings \
                email email/mime email/test email/test/data \
+               json json/tests \
                sqlite3 sqlite3/test \
                logging bsddb bsddb/test csv wsgiref \
-               lib2to3 lib2to3/fixes lib2to3/pgen2 \
+               lib2to3 lib2to3/fixes lib2to3/pgen2 lib2to3/tests \
                ctypes ctypes/test ctypes/macholib idlelib idlelib/Icons \
                distutils distutils/command distutils/tests $(XMLLIBSUBDIRS) \
                setuptools setuptools/command setuptools/tests setuptools.egg-info \
index 2dbd2fd59e16f1777b276ed431a30814023062d7..6eb022d17ca1faccb3133dc38af5aeff5785e495 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -17,6 +17,15 @@ Core and Builtins
   "s#" code already does.  The "z" code was corrected as well.
 
 - Issue 2801: fix bug in the float.is_integer method where a ValueError
+
+- Issue #2863: generators now have a ``gen.__name__`` attribute that equals
+  ``gen.gi_code.co_name``, like ``func.__name___`` that equals
+  ``func.func_code.co_name``.  The repr() of a generator now also contains
+  this name.
+
+- Issue #2831: enumerate() now has a ``start`` argument.
+
+- Issue #2801: fix bug in the float.is_integer method where a ValueError
   was sometimes incorrectly raised.
 
 - The --with-toolbox-glue option (and the associated pymactoolbox.h) have been
diff --git a/Misc/TextMate/Python-Dev.tmbundle/Snippets/2 to 3 - Module Deletion (docs).tmSnippet b/Misc/TextMate/Python-Dev.tmbundle/Snippets/2 to 3 - Module Deletion (docs).tmSnippet
new file mode 100644 (file)
index 0000000..5de8bae
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+       <key>content</key>
+       <string>.. deprecated:: 2.6
+   The :mod:\`${1}\` module has been deprecated for removal in Python 3.0.
+${0}</string>
+       <key>name</key>
+       <string>2 to 3 - Module Deletion (docs)</string>
+       <key>tabTrigger</key>
+       <string>2to3docdel</string>
+       <key>uuid</key>
+       <string>0568410D-EAF1-4AF3-B6DE-8AF133A91821</string>
+</dict>
+</plist>
index 644bc7e5ddec0a5215c230b5ec0d4137abac370c..0510d5d4eed6b05aad471225695aa070d24744a6 100644 (file)
@@ -7,6 +7,7 @@
                <key>items</key>
                <array>
                        <string>9519C22B-6AB8-41A1-94F6-079E0B45C147</string>
+                       <string>0568410D-EAF1-4AF3-B6DE-8AF133A91821</string>
                        <string>------------------------------------</string>
                        <string>B545BB1B-A8E1-426C-B50A-426E78B96D38</string>
                        <string>6EF151E5-7149-4F82-8796-0CC40FE589FA</string>
@@ -23,6 +24,7 @@
        <key>ordering</key>
        <array>
                <string>9519C22B-6AB8-41A1-94F6-079E0B45C147</string>
+               <string>0568410D-EAF1-4AF3-B6DE-8AF133A91821</string>
                <string>B545BB1B-A8E1-426C-B50A-426E78B96D38</string>
                <string>6EF151E5-7149-4F82-8796-0CC40FE589FA</string>
                <string>FD25A8DC-22DC-4ED4-B222-B943C8A9117D</string>
index 5a08e6defe3c6aef498692670a6a93b00c2e4ce5..08c7c096cad227eedfdd45178dd94455cf08505f 100644 (file)
@@ -15,18 +15,29 @@ enum_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
        enumobject *en;
        PyObject *seq = NULL;
-       static char *kwlist[] = {"sequence", 0};
+       PyObject *start = NULL;
+       static char *kwlist[] = {"sequence", "start", 0};
 
-       if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:enumerate", kwlist,
-                                        &seq))
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:enumerate", kwlist,
+                                        &seq, &start))
                return NULL;
 
        en = (enumobject *)type->tp_alloc(type, 0);
        if (en == NULL)
                return NULL;
-       en->en_index = 0;
+       if (start) {
+               start = PyNumber_Index(start);
+               if (start == NULL) {
+                       Py_DECREF(en);
+                       return NULL;
+               }
+               en->en_index = LONG_MAX;
+               en->en_longindex = start;
+       } else {
+               en->en_index = 0;
+               en->en_longindex = NULL;
+       }
        en->en_sit = PyObject_GetIter(seq);
-       en->en_longindex = NULL;
        if (en->en_sit == NULL) {
                Py_DECREF(en);
                return NULL;
index 589786736db0b749e6e0e18b2b02a57fa715857b..c76bcb686d27290928d3241c46ed92e2f70743e5 100644 (file)
@@ -282,6 +282,33 @@ gen_iternext(PyGenObject *gen)
 }
 
 
+static PyObject *
+gen_repr(PyGenObject *gen)
+{
+       return PyUnicode_FromFormat("<%S generator object at %p>",
+                                   ((PyCodeObject *)gen->gi_code)->co_name,
+                                   gen);
+}
+
+
+static PyObject *
+gen_get_name(PyGenObject *gen)
+{
+       PyObject *name = ((PyCodeObject *)gen->gi_code)->co_name;
+       Py_INCREF(name);
+       return name;
+}
+
+
+PyDoc_STRVAR(gen__name__doc__,
+"Return the name of the generator's associated code object.");
+
+static PyGetSetDef gen_getsetlist[] = {
+       {"__name__", (getter)gen_get_name, NULL, NULL, gen__name__doc__},
+       {NULL}
+};
+
+
 static PyMemberDef gen_memberlist[] = {
        {"gi_frame",    T_OBJECT, offsetof(PyGenObject, gi_frame),      READONLY},
        {"gi_running",  T_INT,    offsetof(PyGenObject, gi_running),    READONLY},
@@ -307,7 +334,7 @@ PyTypeObject PyGen_Type = {
        0,                                      /* tp_getattr */
        0,                                      /* tp_setattr */
        0,                                      /* tp_compare */
-       0,                                      /* tp_repr */
+       (reprfunc)gen_repr,                     /* tp_repr */
        0,                                      /* tp_as_number */
        0,                                      /* tp_as_sequence */
        0,                                      /* tp_as_mapping */
@@ -327,7 +354,7 @@ PyTypeObject PyGen_Type = {
        (iternextfunc)gen_iternext,             /* tp_iternext */
        gen_methods,                            /* tp_methods */
        gen_memberlist,                         /* tp_members */
-       0,                                      /* tp_getset */
+       gen_getsetlist,                         /* tp_getset */
        0,                                      /* tp_base */
        0,                                      /* tp_dict */
 
index 12b102125421dabebc7b6a37bfc513ee6c7978a9..8ccd4bb54a38b3744897b0028311f0a8add60091 100644 (file)
@@ -408,8 +408,10 @@ warn_explicit(PyObject *category, PyObject *message,
                 /* A proper implementation of warnings.showwarning() should
                     have at least two default arguments. */
                 if ((defaults == NULL) || (PyTuple_Size(defaults) < 2)) {
-                    if (PyErr_WarnEx(PyExc_DeprecationWarning, msg, 1) < 0)
+                    if (PyErr_WarnEx(PyExc_DeprecationWarning, msg, 1) < 0) {
+                        Py_DECREF(show_fxn);
                         goto cleanup;
+                    }
                 }
                 res = PyObject_CallFunctionObjArgs(show_fxn, message, category,
                                                     filename, lineno_obj,
index 94a27154431968b4bce34c309d1823a6774a0d4b..6cc5c4acbd8156796c82596661c40a8873384000 100644 (file)
@@ -2984,7 +2984,7 @@ compiler_genexp(struct compiler *c, expr_ty e)
 {
        static identifier name;
        if (!name) {
-               name = PyUnicode_FromString("<genexp>");
+               name = PyUnicode_FromString("<genexpr>");
                if (!name)
                        return 0;
        }