/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/symbol_versioning.py

  • Committer: Robert Collins
  • Date: 2006-01-05 11:03:07 UTC
  • mto: (1534.1.2 integration)
  • mto: This revision was merged to the branch mainline in revision 1536.
  • Revision ID: robertc@robertcollins.net-20060105110307-21db4cbdfd94f2c6
Implement deprecated_function.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
    warn = method
38
38
 
39
39
 
 
40
# TODO - maybe this would be easier to use as one 'smart' method that
 
41
# guess if it is a method or a class or an attribute ? If so, we can
 
42
# add that on top of the primitives, once we have all three written
 
43
# - RBC 20050105
 
44
 
 
45
def deprecated_function(deprecation_version):
 
46
    """Decorate a function so that use of it will trigger a warning."""
 
47
 
 
48
    def function_decorator(callable):
 
49
        """This is the function python calls to perform the decoration."""
 
50
        
 
51
        def decorated_function(*args, **kwargs):
 
52
            """This is the decorated method."""
 
53
            symbol = "%s.%s" % (callable.__module__, 
 
54
                                callable.__name__
 
55
                                )
 
56
            warn(deprecation_version % symbol, DeprecationWarning)
 
57
            return callable(*args, **kwargs)
 
58
        return decorated_function
 
59
    return function_decorator
 
60
 
 
61
 
40
62
def deprecated_method(deprecation_version):
41
63
    """Decorate a method so that use of it will trigger a warning.
42
64