Browse Source

more warnings described and solutions given

master
Julio Biason 10 years ago
parent
commit
63cf1ec6a2
  1. 637
      pylint.html

637
pylint.html

@ -1,266 +1,407 @@
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Pylint, Warnings e Correções</title> <title>Pylint, Warnings e Correções</title>
<meta name="author" content="Julio Biason"> <meta name="author" content="Julio Biason">
<meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" /> <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="_external/reveal.min.css"> <link rel="stylesheet" href="_external/reveal.min.css">
<link rel="stylesheet" href="_external/night.css" id="theme"> <link rel="stylesheet" href="_external/night.css" id="theme">
<!-- For syntax highlighting --> <!-- For syntax highlighting -->
<link rel="stylesheet" href="_external/zenburn.css"> <link rel="stylesheet" href="_external/zenburn.css">
<!-- If the query includes 'print-pdf', include the PDF print sheet --> <!-- If the query includes 'print-pdf', include the PDF print sheet -->
<script> <script>
if( window.location.search.match( /print-pdf/gi ) ) { if( window.location.search.match( /print-pdf/gi ) ) {
var link = document.createElement( 'link' ); var link = document.createElement( 'link' );
link.rel = 'stylesheet'; link.rel = 'stylesheet';
link.type = 'text/css'; link.type = 'text/css';
link.href = '_external/pdf.css'; link.href = '_external/pdf.css';
document.getElementsByTagName( 'head' )[0].appendChild( link ); document.getElementsByTagName( 'head' )[0].appendChild( link );
} }
</script> </script>
<!--[if lt IE 9]> <!--[if lt IE 9]>
<script src="reveal.js/lib/js/html5shiv.js"></script> <script src="reveal.js/lib/js/html5shiv.js"></script>
<![endif]--> <![endif]-->
<style> <style>
.semi-opaque { .semi-opaque {
background-color: rgba(0, 0, 0, 0.7); background-color: rgba(0, 0, 0, 0.7);
} }
* { * {
hyphens: none !important; hyphens: none !important;
-moz-hyphens: none !important; -moz-hyphens: none !important;
} }
</style>
</head> div.code {
font-size: 150%
<body> }
<div class="reveal"> </style>
<!-- Any section element inside of this container is displayed as a slide --> </head>
<div class="slides">
<section data-background='_images/pylint.png' class='semi-opaque'> <body>
<h1>Pylint, Warnings e Correções</h1> <div class="reveal">
</section> <!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section> <section data-background='_images/pylint.png' class='semi-opaque'>
<section> <h1>Pylint, Warnings e Correções</h1>
<h2><code>missing-docstring</code></h2> </section>
</section>
<section>
<section> <section>
<h2>O que é o erro:</h2> <h2><code>missing-docstring</code></h2>
<div style='font-size: 150%'> </section>
<p><pre><code data-trim>
<section>
<h2>O que é o erro</h2>
<div class='code'>
<p><pre><code data-trim class='python'>
def funcao(valor): def funcao(valor):
return valor * 2 return valor * 2
</code></pre></p> </code></pre></p>
</div> </div>
</section> </section>
<section> <section>
<h2>Solução:</h2> <h2>Solução</h2>
<p>Documente suas funções!</p> <p>Documente suas funções!</p>
</section> </section>
</section> </section>
<section> <section>
<section> <section>
<h2><code>wildcard-import</code></h2> <h2><code>wildcard-import</code></h2>
</section> </section>
</section>
<section>
<section> <h2>O que é o erro</h2>
<section> <div class='code'>
<h2><code>unused-import</code></h2> <p><pre><code data-trim class='python'>
</section> from module import *
</section> </code></pre></p>
</div>
<section> </section>
<section>
<h2><code>unused-argument</code></h2> <section>
</section> <h2>Solução</h2>
</section>
<p>Importe apenas as funções módulos que são usados.</p>
<section> </section>
<section>
<h2><code>bare-except</code></h2> <section>
</section> <h2>Por que não usar "import *"</h2>
</section>
<ul>
<section> <li>O módulo pode ter código não protegido por
<section> função, classe ou <code>if __name__ == '__main__'</code></li>
<h2><code>no-self-use</code></h2> <li>Poluíção do namespace.</li>
</section> <li>Módulo pode redefinir uma função presente no
</section> módulo atual.</li>
</ul>
<section> </section>
<section> </section>
<h2><code>old-style-class</code></h2>
</section> <section>
</section> <section>
<h2><code>unused-import</code></h2>
<section> </section>
<section>
<h2><code>super-on-old-class</code></h2> <section>
</section> <h2>O que é o erro</h2>
</section>
<div class='code'>
<section> <p><pre><code data-trim class='python'>
<section> from module import function
<h2><code>no-init</code></h2> </code></pre></p>
</section> </div>
</section>
<p>(E <code>function()</code> não é usado em lugar algum.)</p>
<section> </section>
<section>
<h2><code>super-init-not-called</code></h2> <section>
</section> <h2>Solução</h2>
</section>
<p>Remova o import.</p>
<section> </section>
<section>
<h2><code>attribute-defined-outside-init</code></h2> <section>
</section> <h2>Dica!</h2>
</section>
<p>Quebrar imports em várias linhas facilita correção desse
<section> tipo de problema.</p>
<section>
<h2><code>abstract-method</code></h2> <div class='code'>
</section> <p><pre><code data-trim class='python'>
</section> from module import func1
from module import func2
<section> </pre></code></p>
<section> </div>
<h2><code>arguments-differ</code></h2> </section>
</section> </section>
</section>
<section>
<section> <section>
<section> <h2><code>unused-argument</code></h2>
<h2><code>no-member</code> e <code>maybe-no-member</code></h2> </section>
</section>
</section> <section>
<h2>O que é o erro</h2>
<section>
<section> <div class='code'>
<h2><code>no-value-for-parameter</code></h2> <p><pre><code data-trim>
</section> def func(arg1, arg2):
</section> return arg1 * 2
</pre></code></p>
<section> </div>
<section> </section>
<h2><code>protected-access</code></h2>
</section> <section>
</section> <h2>Solução</h2>
<section> <ul>
<section> <li>Remova o parâmetro desnecessário</li>
<h2><code>too-few-public-methods</code></h2> <li>Altere o parâmetro para "_"</li>
</section> </ul>
</section> </section>
<section> <section>
<section> <h2>Corner case</h2>
<h2><code>too-many-ancestors</code></h2>
</section> <div class='code'>
</section> <p><pre><code data-trim class='python'>
def addSeven(foo): # "Unused argument 'foo'"
<section> foo += [7]
<section> </code></pre></p>
<h2><code>too-many-arguments</code></h2> </div>
</section>
</section> <p>O problema é a questão de referência para objetos
mutáveis. O código em si está errado.</p>
<section> </section>
<section> </section>
<h2><code>too-many-branches</code></h2>
</section> <section>
</section> <section>
<h2><code>bare-except</code></h2>
<section> </section>
<section>
<h2><code>too-many-instance-attributes</code></h2> <section>
</section> <h2>O que é o erro</h2>
</section>
<div class='code'>
<section> <p><pre><code data-trim class='python'>
<section> try:
<h2><code>too-many-lines</code></h2> func()
</section> except Exception e:
</section> pass
</code></pre></p>
<section> </div>
<section> </section>
<h2><code>too-many-locals</code></h2>
</section> <section>
</section> <h2>Solução</h2>
<section> <p>Capture apenas as exceções que você sabe lidar.</p>
<section> </section>
<h2><code>too-many-public-methods</code></h2> </section>
</section>
</section> <section>
<section>
<section> <h2><code>no-self-use</code></h2>
<section> </section>
<h2><code>too-many-statements</code></h2>
</section> <section>
</section> <h2>O que é o erro</h2>
<section> <div class='code'>
<section> <p><pre><code data-trim class='python'>
<h2><code>invalid-name</code></h2> class A(object):
</section> def func(self, a):
</section> return a * 2
</code></pre></p>
<section> </div>
<section> </section>
<h2><code>star-args</code></h2>
</section> <section>
</section> <h2>Solução</h2>
</div>
</div> <p>A solução mais "correta" é tirar a função da classe e deixar
fora do objeto.</p>
<script src="_external/head.min.js"></script>
<script src="_external/reveal.min.js"></script> <p class='fragment'>Não sendo possível,
<code># pylint:disable=no-self-use</code> antes da função.
<script> </p>
</section>
// Full list of configuration options available here: </section>
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({ <section>
controls: true, <section>
progress: true, <h2><code>old-style-class</code></h2>
history: true, </section>
center: true, </section>
theme: 'night', <section>
transition: 'linear', <section>
<h2><code>super-on-old-class</code></h2>
// Optional libraries used to extend on reveal.js </section>
dependencies: [ </section>
{ src: '_external/classList.js', condition: function() { return !document.body.classList; } },
{ src: '_external/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, <section>
{ src: '_external/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, <section>
{ src: '_external/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }, <h2><code>no-init</code></h2>
{ src: '_external/zoom.js', async: true, condition: function() { return !!document.body.classList; } }, </section>
{ src: '_external/notes.js', async: true, condition: function() { return !!document.body.classList; } } </section>
]
}); <section>
<section>
</script> <h2><code>super-init-not-called</code></h2>
</section>
</body> </section>
<section>
<section>
<h2><code>attribute-defined-outside-init</code></h2>
</section>
</section>
<section>
<section>
<h2><code>abstract-method</code></h2>
</section>
</section>
<section>
<section>
<h2><code>arguments-differ</code></h2>
</section>
</section>
<section>
<section>
<h2><code>no-member</code> e <code>maybe-no-member</code></h2>
</section>
</section>
<section>
<section>
<h2><code>no-value-for-parameter</code></h2>
</section>
</section>
<section>
<section>
<h2><code>protected-access</code></h2>
</section>
</section>
<section>
<section>
<h2><code>too-few-public-methods</code></h2>
</section>
</section>
<section>
<section>
<h2><code>too-many-ancestors</code></h2>
</section>
</section>
<section>
<section>
<h2><code>too-many-arguments</code></h2>
</section>
</section>
<section>
<section>
<h2><code>too-many-branches</code></h2>
</section>
</section>
<section>
<section>
<h2><code>too-many-instance-attributes</code></h2>
</section>
</section>
<section>
<section>
<h2><code>too-many-lines</code></h2>
</section>
</section>
<section>
<section>
<h2><code>too-many-locals</code></h2>
</section>
</section>
<section>
<section>
<h2><code>too-many-public-methods</code></h2>
</section>
</section>
<section>
<section>
<h2><code>too-many-statements</code></h2>
</section>
</section>
<section>
<section>
<h2><code>invalid-name</code></h2>
</section>
</section>
<section>
<section>
<h2><code>star-args</code></h2>
</section>
</section>
</div>
</div>
<script src="_external/head.min.js"></script>
<script src="_external/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
theme: 'night',
transition: 'linear',
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: '_external/classList.js', condition: function() { return !document.body.classList; } },
{ src: '_external/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: '_external/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: '_external/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: '_external/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: '_external/notes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html> </html>
<!-- vim:set et ts=4 sts=4 st=4: >

Loading…
Cancel
Save