Rev 3434: Bring back always in the form of 'override'. in http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/dep_warnings

John Arbash Meinel john at arbash-meinel.com
Thu May 29 00:20:45 BST 2008


At http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/dep_warnings

------------------------------------------------------------
revno: 3434
revision-id: john at arbash-meinel.com-20080528232033-cx3l3yg845udklps
parent: john at arbash-meinel.com-20080528231330-k9ger42pvc1eiw1l
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: dep_warnings
timestamp: Wed 2008-05-28 18:20:33 -0500
message:
  Bring back always in the form of 'override'.
  Change the functions so that they are compatible with the released
  definition, and just allow callers to supply override=False
  if they want the new behavior.
modified:
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/commands.py             bzr.py-20050309040720-d10f4714595cf8c3
  bzrlib/symbol_versioning.py    symbol_versioning.py-20060105104851-9ecf8af605d15a80
  bzrlib/tests/test_symbol_versioning.py test_symbol_versioning.py-20060105104851-51d7722c2018d42b
-------------- next part --------------
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2008-05-28 23:13:30 +0000
+++ b/bzrlib/builtins.py	2008-05-28 23:20:33 +0000
@@ -2657,7 +2657,7 @@
         from bzrlib.benchmarks import tree_creator
 
         # Make deprecation warnings visible, unless -Werror is set
-        symbol_versioning.activate_deprecation_warnings()
+        symbol_versioning.activate_deprecation_warnings(override=False)
 
         if cache_dir is not None:
             tree_creator.TreeCreator.CACHE_ROOT = osutils.abspath(cache_dir)

=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2008-05-28 21:53:46 +0000
+++ b/bzrlib/commands.py	2008-05-28 23:20:33 +0000
@@ -828,7 +828,7 @@
     # Is this a final release version? If so, we should suppress warnings
     if bzrlib.version_info[3] == 'final':
         from bzrlib import symbol_versioning
-        symbol_versioning.suppress_deprecation_warnings()
+        symbol_versioning.suppress_deprecation_warnings(override=False)
     try:
         argv = [a.decode(bzrlib.user_encoding) for a in argv[1:]]
     except UnicodeDecodeError:

=== modified file 'bzrlib/symbol_versioning.py'
--- a/bzrlib/symbol_versioning.py	2008-05-28 23:13:30 +0000
+++ b/bzrlib/symbol_versioning.py	2008-05-28 23:20:33 +0000
@@ -348,22 +348,25 @@
     return False
 
 
-def suppress_deprecation_warnings():
+def suppress_deprecation_warnings(override=True):
     """Call this function to suppress all deprecation warnings.
 
     When this is a final release version, we don't want to annoy users with
     lots of deprecation warnings. We only want the deprecation warnings when
     running a dev or release candidate.
+
+    :param override: If True, always set the ignore, if False, only set the
+        ignore if there isn't already a filter.
     """
     import warnings
-    if _check_for_filter(False):
+    if not override and _check_for_filter(error_only=False):
         # If there is already a filter effecting suppress_deprecation_warnings,
         # then skip it.
         return
     warnings.filterwarnings('ignore', category=DeprecationWarning)
 
 
-def activate_deprecation_warnings():
+def activate_deprecation_warnings(override=True):
     """Call this function to activate deprecation warnings.
 
     When running in a 'final' release we suppress deprecation warnings.
@@ -373,9 +376,13 @@
     Note: warnings that have already been issued under 'ignore' will not be
     reported after this point. The 'warnings' module has already marked them as
     handled, so they don't get issued again.
+
+    :param override: If False, only add a filter if there isn't an error filter
+        already. (This slightly differs from suppress_deprecation_warnings, in
+        because it always overrides everything but -Werror).
     """
     import warnings
-    if _check_for_filter(True):
+    if not override and _check_for_filter(error_only=True):
         # DeprecationWarnings are already turned into errors, don't downgrade
         # them to 'default'.
         return

=== modified file 'bzrlib/tests/test_symbol_versioning.py'
--- a/bzrlib/tests/test_symbol_versioning.py	2008-05-28 23:13:30 +0000
+++ b/bzrlib/tests/test_symbol_versioning.py	2008-05-28 23:20:33 +0000
@@ -233,21 +233,24 @@
 
     def test_suppress_deprecation_with_warning_filter(self):
         """don't suppress if we already have a filter"""
-        warnings.filterwarnings('ignore', category=Warning)
-        self.assertFirstWarning('ignore', Warning)
+        warnings.filterwarnings('error', category=Warning)
+        self.assertFirstWarning('error', Warning)
         self.assertEqual(1, len(warnings.filters))
-        symbol_versioning.suppress_deprecation_warnings()
-        self.assertFirstWarning('ignore', Warning)
+        symbol_versioning.suppress_deprecation_warnings(override=False)
+        self.assertFirstWarning('error', Warning)
         self.assertEqual(1, len(warnings.filters))
 
     def test_suppress_deprecation_with_filter(self):
         """don't suppress if we already have a filter"""
-        warnings.filterwarnings('ignore', category=DeprecationWarning)
-        self.assertFirstWarning('ignore', DeprecationWarning)
-        self.assertEqual(1, len(warnings.filters))
-        symbol_versioning.suppress_deprecation_warnings()
-        self.assertFirstWarning('ignore', DeprecationWarning)
-        self.assertEqual(1, len(warnings.filters))
+        warnings.filterwarnings('error', category=DeprecationWarning)
+        self.assertFirstWarning('error', DeprecationWarning)
+        self.assertEqual(1, len(warnings.filters))
+        symbol_versioning.suppress_deprecation_warnings(override=False)
+        self.assertFirstWarning('error', DeprecationWarning)
+        self.assertEqual(1, len(warnings.filters))
+        symbol_versioning.suppress_deprecation_warnings(override=True)
+        self.assertFirstWarning('ignore', DeprecationWarning)
+        self.assertEqual(2, len(warnings.filters))
 
     def test_activate_deprecation_no_error(self):
         # First nuke the filters, so we know it is clean
@@ -260,7 +263,7 @@
         warnings.filterwarnings('error', category=Warning)
         self.assertFirstWarning('error', Warning)
         self.assertEqual(1, len(warnings.filters))
-        symbol_versioning.activate_deprecation_warnings()
+        symbol_versioning.activate_deprecation_warnings(override=False)
         # There should not be a new warning
         self.assertFirstWarning('error', Warning)
         self.assertEqual(1, len(warnings.filters))
@@ -271,7 +274,10 @@
         warnings.filterwarnings('error', category=DeprecationWarning)
         self.assertFirstWarning('error', DeprecationWarning)
         self.assertEqual(1, len(warnings.filters))
-        symbol_versioning.activate_deprecation_warnings()
+        symbol_versioning.activate_deprecation_warnings(override=False)
         # There should not be a new warning
         self.assertFirstWarning('error', DeprecationWarning)
         self.assertEqual(1, len(warnings.filters))
+        symbol_versioning.activate_deprecation_warnings(override=True)
+        self.assertFirstWarning('default', DeprecationWarning)
+        self.assertEqual(2, len(warnings.filters))



More information about the bazaar-commits mailing list