/usr/share/doc/python-debtcollector-doc/html/examples.html is in python-debtcollector-doc 1.5.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Examples — debtcollector documentation</title>
<link rel="stylesheet" href="_static/nature.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/tweaks.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="top" title="debtcollector documentation" href="index.html" />
<link rel="next" title="Contributing" href="contributing.html" />
<link rel="prev" title="API" href="api.html" />
</head>
<body role="document">
<div id="header">
<h1 id="logo"><a href="http://www.openstack.org/">OpenStack</a></h1>
<ul id="navigation">
<li><a href="http://www.openstack.org/" title="Go to the Home page" class="link">Home</a></li>
<li><a href="http://www.openstack.org/projects/" title="Go to the OpenStack Projects page">Projects</a></li>
<li><a href="http://www.openstack.org/user-stories/" title="Go to the User Stories page" class="link">User Stories</a></li>
<li><a href="http://www.openstack.org/community/" title="Go to the Community page" class="link">Community</a></li>
<li><a href="http://www.openstack.org/blog/" title="Go to the OpenStack Blog">Blog</a></li>
<li><a href="http://wiki.openstack.org/" title="Go to the OpenStack Wiki">Wiki</a></li>
<li><a href="http://docs.openstack.org/" title="Go to OpenStack Documentation" class="current">Documentation</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="examples">
<h1>Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h1>
<div class="section" id="removing-a-class-classmethod-method-function">
<h2>Removing a class/classmethod/method/function<a class="headerlink" href="#removing-a-class-classmethod-method-function" title="Permalink to this headline">¶</a></h2>
<p>To signal to a user that a method (staticmethod, classmethod, or regular
instance method) or a class or function is going to be removed at some point
in the future the <a class="reference internal" href="api.html#debtcollector.removals.remove" title="debtcollector.removals.remove"><code class="xref py py-func docutils literal"><span class="pre">remove()</span></code></a> function/decorator
can be used to achieve this in a non-destructive manner.</p>
<p>A basic example to do just this (on a method/function):</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">debtcollector</span> <span class="k">import</span> <span class="n">removals</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">warnings</span>
<span class="gp">>>> </span><span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s1">'always'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">class</span> <span class="nc">Car</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="gp">... </span> <span class="nd">@removals</span><span class="o">.</span><span class="n">remove</span>
<span class="gp">... </span> <span class="k">def</span> <span class="nf">start</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">pass</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">c</span> <span class="o">=</span> <span class="n">Car</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
</pre></div>
</div>
<p><strong>Expected output:</strong></p>
<div class="highlight-none"><div class="highlight"><pre><span></span>__main__:1: DeprecationWarning: Using function/method 'Car.start()' is deprecated
</pre></div>
</div>
<p>A basic example to do just this (on a class):</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">debtcollector</span> <span class="k">import</span> <span class="n">removals</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">warnings</span>
<span class="gp">>>> </span><span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s1">'always'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nd">@removals</span><span class="o">.</span><span class="n">removed_class</span><span class="p">(</span><span class="s2">"Pinto"</span><span class="p">)</span>
<span class="gp">... </span><span class="k">class</span> <span class="nc">Pinto</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">pass</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">Pinto</span><span class="p">()</span>
</pre></div>
</div>
<p><strong>Expected output:</strong></p>
<div class="highlight-none"><div class="highlight"><pre><span></span>__main__:1: DeprecationWarning: Using class 'Pinto' (either directly or via inheritance) is deprecated
</pre></div>
</div>
<p>A basic example to do just this (on a classmethod):</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">debtcollector</span> <span class="k">import</span> <span class="n">removals</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">warnings</span>
<span class="gp">>>> </span><span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s2">"once"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">class</span> <span class="nc">OldAndBusted</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="gp">... </span> <span class="nd">@removals</span><span class="o">.</span><span class="n">remove</span>
<span class="gp">... </span> <span class="nd">@classmethod</span>
<span class="gp">... </span> <span class="k">def</span> <span class="nf">fix_things</span><span class="p">(</span><span class="n">cls</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">pass</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">OldAndBusted</span><span class="o">.</span><span class="n">fix_things</span><span class="p">()</span>
</pre></div>
</div>
<p><strong>Expected output:</strong></p>
<div class="highlight-none"><div class="highlight"><pre><span></span>__main__:1: DeprecationWarning: Using function/method 'OldAndBusted.fix_things()' is deprecated
</pre></div>
</div>
</div>
<div class="section" id="removing-a-instance-property">
<h2>Removing a instance property<a class="headerlink" href="#removing-a-instance-property" title="Permalink to this headline">¶</a></h2>
<p>Use the <a class="reference internal" href="api.html#debtcollector.removals.removed_property" title="debtcollector.removals.removed_property"><code class="xref py py-func docutils literal"><span class="pre">removed_property()</span></code></a> decorator
to signal that an attribute of a class is deprecated.</p>
<p>A basic example to do just this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">warnings</span>
<span class="gp">>>> </span><span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s2">"once"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">debtcollector</span> <span class="k">import</span> <span class="n">removals</span>
<span class="gp">>>> </span><span class="k">class</span> <span class="nc">OldAndBusted</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="gp">... </span> <span class="nd">@removals</span><span class="o">.</span><span class="n">removed_property</span>
<span class="gp">... </span> <span class="k">def</span> <span class="nf">thing</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">return</span> <span class="s1">'old-and-busted'</span>
<span class="gp">... </span> <span class="nd">@thing</span><span class="o">.</span><span class="n">setter</span>
<span class="gp">... </span> <span class="k">def</span> <span class="nf">thing</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">pass</span>
<span class="gp">... </span> <span class="nd">@thing</span><span class="o">.</span><span class="n">deleter</span>
<span class="gp">... </span> <span class="k">def</span> <span class="nf">thing</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">pass</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">o</span> <span class="o">=</span> <span class="n">OldAndBusted</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">o</span><span class="o">.</span><span class="n">thing</span>
<span class="go">'old-and-busted'</span>
<span class="gp">>>> </span><span class="n">o</span><span class="o">.</span><span class="n">thing</span> <span class="o">=</span> <span class="s1">'2'</span>
<span class="gp">>>> </span><span class="k">del</span> <span class="n">o</span><span class="o">.</span><span class="n">thing</span>
</pre></div>
</div>
<div class="highlight-none"><div class="highlight"><pre><span></span>__main__:1: DeprecationWarning: Reading the 'thing' property is deprecated
__main__:1: DeprecationWarning: Setting the 'thing' property is deprecated
__main__:1: DeprecationWarning: Deleting the 'thing' property is deprecated
</pre></div>
</div>
</div>
<div class="section" id="removing-a-keyword-argument">
<h2>Removing a keyword argument<a class="headerlink" href="#removing-a-keyword-argument" title="Permalink to this headline">¶</a></h2>
<p>A basic example to do just this (on a classmethod):</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">warnings</span>
<span class="gp">>>> </span><span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s2">"once"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">debtcollector</span> <span class="k">import</span> <span class="n">removals</span>
<span class="gp">>>> </span><span class="k">class</span> <span class="nc">OldAndBusted</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="gp">... </span> <span class="nd">@removals</span><span class="o">.</span><span class="n">removed_kwarg</span><span class="p">(</span><span class="s1">'resp'</span><span class="p">,</span> <span class="n">message</span><span class="o">=</span><span class="s2">"Please use 'response' instead"</span><span class="p">)</span>
<span class="gp">... </span> <span class="nd">@classmethod</span>
<span class="gp">... </span> <span class="k">def</span> <span class="nf">factory</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">resp</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">response</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="gp">... </span> <span class="n">response</span> <span class="o">=</span> <span class="n">resp</span> <span class="ow">or</span> <span class="n">response</span>
<span class="gp">... </span> <span class="k">return</span> <span class="n">response</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">OldAndBusted</span><span class="o">.</span><span class="n">factory</span><span class="p">(</span><span class="n">resp</span><span class="o">=</span><span class="s1">'super-duper'</span><span class="p">)</span>
<span class="go">'super-duper'</span>
</pre></div>
</div>
<div class="highlight-none"><div class="highlight"><pre><span></span>__main__:1: DeprecationWarning: Using the 'resp' argument is deprecated: Please use 'response' instead
</pre></div>
</div>
<p>A basic example to do just this (on a <code class="docutils literal"><span class="pre">__init__</span></code> method):</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">warnings</span>
<span class="gp">>>> </span><span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s2">"once"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">debtcollector</span> <span class="k">import</span> <span class="n">removals</span>
<span class="gp">>>> </span><span class="k">class</span> <span class="nc">OldAndBusted</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="gp">... </span> <span class="nd">@removals</span><span class="o">.</span><span class="n">removed_kwarg</span><span class="p">(</span><span class="s1">'bleep'</span><span class="p">)</span>
<span class="gp">... </span> <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bleep</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="gp">... </span> <span class="bp">self</span><span class="o">.</span><span class="n">bloop</span> <span class="o">=</span> <span class="n">bleep</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">o</span> <span class="o">=</span> <span class="n">OldAndBusted</span><span class="p">(</span><span class="n">bleep</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-none"><div class="highlight"><pre><span></span>__main__:1: DeprecationWarning: Using the 'bleep' argument is deprecated
</pre></div>
</div>
</div>
<div class="section" id="changing-the-default-value-of-a-keyword-argument">
<h2>Changing the default value of a keyword argument<a class="headerlink" href="#changing-the-default-value-of-a-keyword-argument" title="Permalink to this headline">¶</a></h2>
<p>A basic example to do just this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">warnings</span>
<span class="gp">>>> </span><span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s2">"once"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">debtcollector</span> <span class="k">import</span> <span class="n">updating</span>
<span class="gp">>>> </span><span class="k">class</span> <span class="nc">OldAndBusted</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="gp">... </span> <span class="n">ip</span> <span class="o">=</span> <span class="s1">'127.0.0.1'</span>
<span class="gp">... </span> <span class="nd">@updating</span><span class="o">.</span><span class="n">updated_kwarg_default_value</span><span class="p">(</span><span class="s1">'type'</span><span class="p">,</span> <span class="s1">'http'</span><span class="p">,</span> <span class="s1">'https'</span><span class="p">)</span>
<span class="gp">... </span> <span class="k">def</span> <span class="nf">url</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="s1">'http'</span><span class="p">):</span>
<span class="gp">... </span> <span class="n">response</span> <span class="o">=</span> <span class="s1">'</span><span class="si">%s</span><span class="s1">://</span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span><span class="nb">type</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ip</span><span class="p">)</span>
<span class="gp">... </span> <span class="k">return</span> <span class="n">response</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">OldAndBusted</span><span class="p">()</span><span class="o">.</span><span class="n">url</span><span class="p">()</span>
<span class="go">'http://127.0.0.1'</span>
</pre></div>
</div>
<div class="highlight-none"><div class="highlight"><pre><span></span>__main__:1: FutureWarning: The http argument is changing its default value to https, please update the code to explicitly set http as the value
</pre></div>
</div>
<p>A basic classmethod example.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">the @classmethod decorator is before the debtcollector one</p>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">warnings</span>
<span class="gp">>>> </span><span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s2">"once"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">debtcollector</span> <span class="k">import</span> <span class="n">updating</span>
<span class="gp">>>> </span><span class="k">class</span> <span class="nc">OldAndBusted</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="gp">... </span> <span class="n">ip</span> <span class="o">=</span> <span class="s1">'127.0.0.1'</span>
<span class="gp">... </span> <span class="nd">@classmethod</span>
<span class="gp">... </span> <span class="nd">@updating</span><span class="o">.</span><span class="n">updated_kwarg_default_value</span><span class="p">(</span><span class="s1">'type'</span><span class="p">,</span> <span class="s1">'http'</span><span class="p">,</span> <span class="s1">'https'</span><span class="p">)</span>
<span class="gp">... </span> <span class="k">def</span> <span class="nf">url</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="s1">'http'</span><span class="p">):</span>
<span class="gp">... </span> <span class="n">response</span> <span class="o">=</span> <span class="s1">'</span><span class="si">%s</span><span class="s1">://</span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span><span class="nb">type</span><span class="p">,</span> <span class="n">cls</span><span class="o">.</span><span class="n">ip</span><span class="p">)</span>
<span class="gp">... </span> <span class="k">return</span> <span class="n">response</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">OldAndBusted</span><span class="o">.</span><span class="n">url</span><span class="p">()</span>
<span class="go">'http://127.0.0.1'</span>
</pre></div>
</div>
<div class="highlight-none"><div class="highlight"><pre><span></span>__main__:1: FutureWarning: The http argument is changing its default value to https, please update the code to explicitly set http as the value
</pre></div>
</div>
</div>
<div class="section" id="moving-a-function">
<h2>Moving a function<a class="headerlink" href="#moving-a-function" title="Permalink to this headline">¶</a></h2>
<p>To change the name or location of a regular function use the
<a class="reference internal" href="api.html#debtcollector.moves.moved_function" title="debtcollector.moves.moved_function"><code class="xref py py-func docutils literal"><span class="pre">moved_function()</span></code></a> function:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">debtcollector</span> <span class="k">import</span> <span class="n">moves</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">warnings</span>
<span class="gp">>>> </span><span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s1">'always'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">def</span> <span class="nf">new_thing</span><span class="p">():</span>
<span class="gp">... </span> <span class="k">return</span> <span class="s2">"new thing"</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">old_thing</span> <span class="o">=</span> <span class="n">moves</span><span class="o">.</span><span class="n">moved_function</span><span class="p">(</span><span class="n">new_thing</span><span class="p">,</span> <span class="s1">'old_thing'</span><span class="p">,</span> <span class="n">__name__</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">new_thing</span><span class="p">()</span>
<span class="go">'new thing'</span>
<span class="gp">>>> </span><span class="n">old_thing</span><span class="p">()</span>
<span class="go">'new thing'</span>
</pre></div>
</div>
<p><strong>Expected output:</strong></p>
<div class="highlight-none"><div class="highlight"><pre><span></span>__main__:1: DeprecationWarning: Function '__main__.old_thing()' has moved to '__main__.new_thing()'
</pre></div>
</div>
</div>
<div class="section" id="moving-a-method">
<h2>Moving a method<a class="headerlink" href="#moving-a-method" title="Permalink to this headline">¶</a></h2>
<p>To move a <em>instance</em> method from an existing one to a new one
the <a class="reference internal" href="api.html#debtcollector.moves.moved_method" title="debtcollector.moves.moved_method"><code class="xref py py-func docutils literal"><span class="pre">moved_method()</span></code></a> function/decorator can be
used to achieve this in a non-destructive manner.</p>
<p>A basic example to do just this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">debtcollector</span> <span class="k">import</span> <span class="n">moves</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">warnings</span>
<span class="gp">>>> </span><span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s1">'always'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">class</span> <span class="nc">Cat</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="gp">... </span> <span class="nd">@moves</span><span class="o">.</span><span class="n">moved_method</span><span class="p">(</span><span class="s1">'meow'</span><span class="p">)</span>
<span class="gp">... </span> <span class="k">def</span> <span class="nf">mewow</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">meow</span><span class="p">()</span>
<span class="gp">... </span> <span class="k">def</span> <span class="nf">meow</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">return</span> <span class="s1">'kitty'</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">c</span> <span class="o">=</span> <span class="n">Cat</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">mewow</span><span class="p">()</span>
<span class="go">'kitty'</span>
<span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">meow</span><span class="p">()</span>
<span class="go">'kitty'</span>
</pre></div>
</div>
<p><strong>Expected output:</strong></p>
<div class="highlight-none"><div class="highlight"><pre><span></span>__main__:1: DeprecationWarning: Method 'Cat.mewow()' has moved to 'Cat.meow()'
</pre></div>
</div>
</div>
<div class="section" id="moving-a-property">
<h2>Moving a property<a class="headerlink" href="#moving-a-property" title="Permalink to this headline">¶</a></h2>
<p>To move a <em>instance</em> property from an existing one to a new one
the <a class="reference internal" href="api.html#debtcollector.moves.moved_property" title="debtcollector.moves.moved_property"><code class="xref py py-func docutils literal"><span class="pre">moved_property()</span></code></a> function/decorator can be
used to achieve this in a non-destructive manner.</p>
<p>A basic example to do just this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">debtcollector</span> <span class="k">import</span> <span class="n">moves</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">warnings</span>
<span class="gp">>>> </span><span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s1">'always'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">class</span> <span class="nc">Dog</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="gp">... </span> <span class="nd">@property</span>
<span class="gp">... </span> <span class="nd">@moves</span><span class="o">.</span><span class="n">moved_property</span><span class="p">(</span><span class="s1">'bark'</span><span class="p">)</span>
<span class="gp">... </span> <span class="k">def</span> <span class="nf">burk</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">bark</span>
<span class="gp">... </span> <span class="nd">@property</span>
<span class="gp">... </span> <span class="k">def</span> <span class="nf">bark</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">return</span> <span class="s1">'woof'</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">d</span> <span class="o">=</span> <span class="n">Dog</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">d</span><span class="o">.</span><span class="n">burk</span>
<span class="go">'woof'</span>
<span class="gp">>>> </span><span class="n">d</span><span class="o">.</span><span class="n">bark</span>
<span class="go">'woof'</span>
</pre></div>
</div>
<p><strong>Expected output:</strong></p>
<div class="highlight-none"><div class="highlight"><pre><span></span>__main__:1: DeprecationWarning: Property 'Dog.burk' has moved to 'Dog.bark'
</pre></div>
</div>
</div>
<div class="section" id="moving-a-class">
<h2>Moving a class<a class="headerlink" href="#moving-a-class" title="Permalink to this headline">¶</a></h2>
<p>To move a <em>class</em> from an existing one to a new one
the <a class="reference internal" href="api.html#debtcollector.moves.moved_class" title="debtcollector.moves.moved_class"><code class="xref py py-func docutils literal"><span class="pre">moved_class()</span></code></a> type generator function can
be used to achieve this in a non-destructive manner.</p>
<p>A basic example to do just this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">debtcollector</span> <span class="k">import</span> <span class="n">moves</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">warnings</span>
<span class="gp">>>> </span><span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s1">'always'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">class</span> <span class="nc">WizBang</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">pass</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">OldWizBang</span> <span class="o">=</span> <span class="n">moves</span><span class="o">.</span><span class="n">moved_class</span><span class="p">(</span><span class="n">WizBang</span><span class="p">,</span> <span class="s1">'OldWizBang'</span><span class="p">,</span> <span class="n">__name__</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">OldWizBang</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">b</span> <span class="o">=</span> <span class="n">WizBang</span><span class="p">()</span>
</pre></div>
</div>
<p><strong>Expected output:</strong></p>
<div class="highlight-none"><div class="highlight"><pre><span></span>__main__:1: DeprecationWarning: Class '__main__.OldWizBang' has moved to '__main__.WizBang'
</pre></div>
</div>
</div>
<div class="section" id="renaming-a-keyword-argument">
<h2>Renaming a keyword argument<a class="headerlink" href="#renaming-a-keyword-argument" title="Permalink to this headline">¶</a></h2>
<p>To notify the user when a keyword argument has been replaced with a new and
improved keyword argument and the user is still using the old keyword argument
the <a class="reference internal" href="api.html#debtcollector.renames.renamed_kwarg" title="debtcollector.renames.renamed_kwarg"><code class="xref py py-func docutils literal"><span class="pre">renamed_kwarg()</span></code></a> function/decorator
can be used to achieve this in a non-destructive manner.</p>
<p>A basic example to do just this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">debtcollector</span> <span class="k">import</span> <span class="n">renames</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">warnings</span>
<span class="gp">>>> </span><span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s1">'always'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nd">@renames</span><span class="o">.</span><span class="n">renamed_kwarg</span><span class="p">(</span><span class="s1">'snizzle'</span><span class="p">,</span> <span class="s1">'nizzle'</span><span class="p">)</span>
<span class="gp">... </span><span class="k">def</span> <span class="nf">do_the_deed</span><span class="p">(</span><span class="n">snizzle</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nizzle</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">return</span> <span class="p">(</span><span class="n">snizzle</span><span class="p">,</span> <span class="n">nizzle</span><span class="p">)</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">do_the_deed</span><span class="p">()</span>
<span class="go">(True, True)</span>
<span class="gp">>>> </span><span class="n">do_the_deed</span><span class="p">(</span><span class="n">snizzle</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">(False, True)</span>
<span class="gp">>>> </span><span class="n">do_the_deed</span><span class="p">(</span><span class="n">nizzle</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">(True, False)</span>
</pre></div>
</div>
<p><strong>Expected output:</strong></p>
<div class="highlight-none"><div class="highlight"><pre><span></span>__main__:1: DeprecationWarning: Using the 'snizzle' argument is deprecated, please use the 'nizzle' argument instead
</pre></div>
</div>
</div>
<div class="section" id="further-customizing-the-emitted-messages">
<h2>Further customizing the emitted messages<a class="headerlink" href="#further-customizing-the-emitted-messages" title="Permalink to this headline">¶</a></h2>
<p>It is typically useful to tell the user when a deprecation has started and
when the deprecated item will be offically removed (deleted or other). To
enable this all the currently provided functions this library provides
take a <code class="docutils literal"><span class="pre">message</span></code>, <code class="docutils literal"><span class="pre">version</span></code> and <code class="docutils literal"><span class="pre">removal_version</span></code> keyword arguments.
These are used in forming the message that is shown to the user when they
trigger the deprecated activity.</p>
<p>A basic example to do just this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">debtcollector</span> <span class="k">import</span> <span class="n">renames</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">warnings</span>
<span class="gp">>>> </span><span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s1">'always'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nd">@renames</span><span class="o">.</span><span class="n">renamed_kwarg</span><span class="p">(</span><span class="s1">'snizzle'</span><span class="p">,</span> <span class="s1">'nizzle'</span><span class="p">,</span> <span class="n">version</span><span class="o">=</span><span class="s2">"0.5"</span><span class="p">,</span> <span class="n">removal_version</span><span class="o">=</span><span class="s2">"0.7"</span><span class="p">)</span>
<span class="gp">... </span><span class="k">def</span> <span class="nf">do_the_deed</span><span class="p">(</span><span class="n">snizzle</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nizzle</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">pass</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">do_the_deed</span><span class="p">(</span><span class="n">snizzle</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
</pre></div>
</div>
<p><strong>Expected output:</strong></p>
<div class="highlight-none"><div class="highlight"><pre><span></span>__main__:1: DeprecationWarning: Using the 'snizzle' argument is deprecated in version '0.5' and will be removed in version '0.7', please use the 'nizzle' argument instead
</pre></div>
</div>
<p>If the <code class="docutils literal"><span class="pre">removal_version</span></code> is unknown the special character <code class="docutils literal"><span class="pre">?</span></code> can be used
instead (to denote that the deprecated activity will be removed sometime in
the future).</p>
<p>A basic example to do just this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">debtcollector</span> <span class="k">import</span> <span class="n">renames</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">warnings</span>
<span class="gp">>>> </span><span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s1">'always'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nd">@renames</span><span class="o">.</span><span class="n">renamed_kwarg</span><span class="p">(</span><span class="s1">'snizzle'</span><span class="p">,</span> <span class="s1">'nizzle'</span><span class="p">,</span> <span class="n">version</span><span class="o">=</span><span class="s2">"0.5"</span><span class="p">,</span> <span class="n">removal_version</span><span class="o">=</span><span class="s2">"?"</span><span class="p">)</span>
<span class="gp">... </span><span class="k">def</span> <span class="nf">do_the_deed</span><span class="p">(</span><span class="n">snizzle</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nizzle</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">pass</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">do_the_deed</span><span class="p">(</span><span class="n">snizzle</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
</pre></div>
</div>
<p><strong>Expected output:</strong></p>
<div class="highlight-none"><div class="highlight"><pre><span></span>__main__:1: DeprecationWarning: Using the 'snizzle' argument is deprecated in version '0.5' and will be removed in a future version, please use the 'nizzle' argument instead
</pre></div>
</div>
<p>To further customize the message (with a special postfix) the <code class="docutils literal"><span class="pre">message</span></code>
keyword argument can be provided.</p>
<p>A basic example to do just this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">debtcollector</span> <span class="k">import</span> <span class="n">renames</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">warnings</span>
<span class="gp">>>> </span><span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s1">'always'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nd">@renames</span><span class="o">.</span><span class="n">renamed_kwarg</span><span class="p">(</span><span class="s1">'snizzle'</span><span class="p">,</span> <span class="s1">'nizzle'</span><span class="p">,</span> <span class="n">message</span><span class="o">=</span><span class="s2">"Pretty please stop using it"</span><span class="p">)</span>
<span class="gp">... </span><span class="k">def</span> <span class="nf">do_the_deed</span><span class="p">(</span><span class="n">snizzle</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nizzle</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">pass</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">do_the_deed</span><span class="p">(</span><span class="n">snizzle</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
</pre></div>
</div>
<p><strong>Expected output:</strong></p>
<div class="highlight-none"><div class="highlight"><pre><span></span>__main__:1: DeprecationWarning: Using the 'snizzle' argument is deprecated, please use the 'nizzle' argument instead: Pretty please stop using it
</pre></div>
</div>
</div>
<div class="section" id="deprecating-anything-else">
<h2>Deprecating anything else<a class="headerlink" href="#deprecating-anything-else" title="Permalink to this headline">¶</a></h2>
<p>For use-cases which do not fit the above decorators, properties other
provided functionality the final option is to use debtcollectors
the <a class="reference internal" href="api.html#debtcollector.deprecate" title="debtcollector.deprecate"><code class="xref py py-func docutils literal"><span class="pre">deprecate()</span></code></a> function to make your own
messages (using the message building logic that debtcollector uses itself).</p>
<p>A basic example to do just this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">warnings</span>
<span class="gp">>>> </span><span class="n">warnings</span><span class="o">.</span><span class="n">simplefilter</span><span class="p">(</span><span class="s2">"always"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">debtcollector</span>
<span class="gp">>>> </span><span class="n">debtcollector</span><span class="o">.</span><span class="n">deprecate</span><span class="p">(</span><span class="s2">"This is no longer supported"</span><span class="p">,</span> <span class="n">version</span><span class="o">=</span><span class="s2">"1.0"</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-none"><div class="highlight"><pre><span></span>__main__:1: DeprecationWarning: This is no longer supported in version '1.0'
</pre></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Examples</a><ul>
<li><a class="reference internal" href="#removing-a-class-classmethod-method-function">Removing a class/classmethod/method/function</a></li>
<li><a class="reference internal" href="#removing-a-instance-property">Removing a instance property</a></li>
<li><a class="reference internal" href="#removing-a-keyword-argument">Removing a keyword argument</a></li>
<li><a class="reference internal" href="#changing-the-default-value-of-a-keyword-argument">Changing the default value of a keyword argument</a></li>
<li><a class="reference internal" href="#moving-a-function">Moving a function</a></li>
<li><a class="reference internal" href="#moving-a-method">Moving a method</a></li>
<li><a class="reference internal" href="#moving-a-property">Moving a property</a></li>
<li><a class="reference internal" href="#moving-a-class">Moving a class</a></li>
<li><a class="reference internal" href="#renaming-a-keyword-argument">Renaming a keyword argument</a></li>
<li><a class="reference internal" href="#further-customizing-the-emitted-messages">Further customizing the emitted messages</a></li>
<li><a class="reference internal" href="#deprecating-anything-else">Deprecating anything else</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="api.html"
title="previous chapter">API</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="contributing.html"
title="next chapter">Contributing</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/examples.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="contributing.html" title="Contributing"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="api.html" title="API"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">debtcollector documentation</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2016, OpenStack Foundation.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.8.
</div>
<script type="text/javascript">
try {
//Tracking docs.openstack.org/developer/<projectname> only
//The URL is built from the project variable in conf.py
var pageTracker = _gat._getTracker("UA-17511903-1");
pageTracker._setCookiePath("/developer/debtcollector");
pageTracker._trackPageview();
} catch(err) {}</script>
</body>
</html>
|