Greg writes: > This is one of my top two Java features [1]. ... > [1] The other is compiler recognition of "@deprecated" in doc comments. Hmm... what a good idea! Let's see... what exactly does "@deprecated" DO in Java? Why it causes the compiler to emit a warning if you use the function in question. Not a bad idea. Amusingly enough, the syntax is even the same in Python: ===== code ===== import warnings def deprecated(func): """This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emmitted when the function is used.""" def newFunc(*args, **kwargs): warnings.warn("Call to deprecated function.") return func(*args, **kwargs) return newFunc ===== example ===== >>> @deprecated def func(x,y): return x + y >>> func(3,4) Warning (from warnings module): File "g:/Documents/Personal/Python/deprecated.py", line 10 warnings.warn("Call to deprecated function.") UserWarning: Call to deprecated function. 7 So... shall I go add this to the cookbook? -- Michael Chermside
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4