Rev 4721: Use a class regex to find other signatures to exclude. in http://bazaar.launchpad.net/~jameinel/bzr/2.0.4-pyrex-propagation

John Arbash Meinel john at arbash-meinel.com
Tue Jan 5 04:51:53 GMT 2010


At http://bazaar.launchpad.net/~jameinel/bzr/2.0.4-pyrex-propagation

------------------------------------------------------------
revno: 4721
revision-id: john at arbash-meinel.com-20100105045138-gq8wws3a1vyu3eqs
parent: john at arbash-meinel.com-20100104234527-9k1kh0u5lkhzrd09
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.0.4-pyrex-propagation
timestamp: Mon 2010-01-04 22:51:38 -0600
message:
  Use a class regex to find other signatures to exclude.
-------------- next part --------------
=== modified file 'bzrlib/_known_graph_pyx.pyx'
--- a/bzrlib/_known_graph_pyx.pyx	2010-01-04 23:13:20 +0000
+++ b/bzrlib/_known_graph_pyx.pyx	2010-01-05 04:51:38 +0000
@@ -108,14 +108,14 @@
             parent_keys, child_keys)
 
 
-cdef _KnownGraphNode _get_list_node(lst, Py_ssize_t pos): # no except
+cdef _KnownGraphNode _get_list_node(lst, Py_ssize_t pos):
     cdef PyObject *temp_node
 
     temp_node = PyList_GET_ITEM(lst, pos)
     return <_KnownGraphNode>temp_node
 
 
-cdef _KnownGraphNode _get_tuple_node(tpl, Py_ssize_t pos): # no except
+cdef _KnownGraphNode _get_tuple_node(tpl, Py_ssize_t pos):
     cdef PyObject *temp_node
 
     temp_node = PyTuple_GET_ITEM(tpl, pos)
@@ -211,7 +211,7 @@
     # Note: We don't need to set an 'except clause because _KnownGraphNode is
     #       an object type. However our crude test_source parser doesn't know
     #       how to tell that
-    cdef _KnownGraphNode _get_or_create_node(self, key): # no except
+    cdef _KnownGraphNode _get_or_create_node(self, key):
         cdef PyObject *temp_node
         cdef _KnownGraphNode node
 
@@ -646,7 +646,7 @@
             self._push_node(node, 0)
 
     # Note: _MergeSortNode is an object type so there is an implied except
-    cdef _MergeSortNode _get_ms_node(self, _KnownGraphNode node): # no except
+    cdef _MergeSortNode _get_ms_node(self, _KnownGraphNode node):
         cdef PyObject *temp_node
         cdef _MergeSortNode ms_node
 

=== modified file 'bzrlib/msgeditor.py'
--- a/bzrlib/msgeditor.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/msgeditor.py	2010-01-05 04:51:38 +0000
@@ -215,7 +215,7 @@
     """
     import tempfile
     tmp_fileno, msgfilename = tempfile.mkstemp(prefix='bzr_log.',
-                                               dir='.',
+    #                                           dir='.',
                                                text=True)
     msgfilename = osutils.basename(msgfilename)
     msgfile = os.fdopen(tmp_fileno, 'w')

=== modified file 'bzrlib/tests/test_source.py'
--- a/bzrlib/tests/test_source.py	2010-01-04 23:45:27 +0000
+++ b/bzrlib/tests/test_source.py	2010-01-05 04:51:38 +0000
@@ -379,10 +379,8 @@
         """
         both_exc_and_no_exc = []
         missing_except = []
-        # TODO: Add a class re to find what classes are defined in this module
-        #       A function that returns a class is the same as one that returns
-        #       an 'object', the exception handling is implied
-        except_re = re.compile(r'\s*cdef\s*' # start with cdef
+        class_re = re.compile(r'^(cdef\s+)?class (\w+).*:', re.MULTILINE)
+        except_re = re.compile(r'cdef\s*' # start with cdef
                                r'([\w *]*?)\s*' # this is the return signature
                                r'(\w+)\s*\(' # the function name
                                r'[^)]*\)\s*' # parameters
@@ -391,9 +389,10 @@
                               )
         for fname, text in self.get_source_file_contents(
                 extensions=('.pyx',)):
+            known_classes = set([m[1] for m in class_re.findall(text)])
             cdefs = except_re.findall(text)
             for sig, func, exc_clause, no_exc_comment in cdefs:
-                if not sig:
+                if not sig or sig in known_classes:
                     sig = 'object'
                 if exc_clause and no_exc_comment:
                     both_exc_and_no_exc.append((fname, func))
@@ -409,7 +408,7 @@
         if missing_except:
             error_msg.append('The following functions have fixed return types,'
                              ' but no except clause.')
-            error_msg.append(' Either add an except or append "# no except".')
+            error_msg.append('Either add an except or append "# no except".')
             for fname, func in missing_except:
                 error_msg.append('%s:%s' % (fname, func))
             error_msg.extend(('', ''))



More information about the bazaar-commits mailing list