Favorite non-python language trick?
Edvard Majakari
edvard+news at majakari.net
Wed Jul 6 11:32:24 EDT 2005
Thomas Heller <theller at python.net> writes:
> I don't see what's wrong with this code, and if one wanted, one could
> also implement a decorator which calls warnings.warn when the function
> is called:
>
> def c_buffer(init, size=None):
> "deprecated, use create_string_buffer instead"
> import warnings
> warnings.warn("c_buffer is deprecated, use create_string_buffer instead",
> DeprecationWarning, stacklevel=2)
> return create_string_buffer(init, size)
Well, nothing's wrong there, and the same could be done with Java
before. However, having a consistent deprecated string everywhere allows
easier eg. automatic finding of such methods from documentation.
Decorators also help here, but that requires version 2.3 or newer (which
usually isn't a problem, but can be)
Hey! I hadn't realized category parameter nor stacklevel in warnings module
(just used a few times, never read the doc because I didn't need to). Neat,
thanks.
--
# Edvard Majakari Software Engineer
# PGP PUBLIC KEY available Soli Deo Gloria!
$_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print
join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60281449,'es'),2,4),"\n";
More information about the Python-list
mailing list