Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't pass <code>**locals()</code> to functions, do you?</p> <p>Since Python lacks an "include" statement, <em>and</em> the <code>self</code> parameter is explicit, <em>and</em> scoping rules are quite simple, it's usually very easy to point a finger at a variable and tell where that object comes from -- without reading other modules and without any kind of IDE (which are limited in the way of introspection anyway, by the fact the language is very dynamic).</p> <p>The <code>import *</code> breaks all that.</p> <p>Also, it has a concrete possibility of hiding bugs.</p> <pre><code>import os, sys, foo, sqlalchemy, mystuff from bar import * </code></pre> <p>Now, if the bar module has any of the "<code>os</code>", "<code>mystuff</code>", etc... attributes, they will override the explicitly imported ones, and possibly point to very different things. Defining <code>__all__</code> in bar is often wise -- this states what will implicitly be imported - but still it's hard to trace where objects come from, without reading and parsing the bar module and following <em>its</em> imports. A network of <code>import *</code> is the first thing I fix when I take ownership of a project.</p> <p>Don't misunderstand me: if the <code>import *</code> were missing, I would cry to have it. But it has to be used carefully. A good use case is to provide a facade interface over another module. Likewise, the use of conditional import statements, or imports inside function/class namespaces, requires a bit of discipline.</p> <p>I think in medium-to-big projects, or small ones with several contributors, a minimum of hygiene is needed in terms of statical analysis -- running at least pyflakes or even better a properly configured pylint -- to catch several kind of bugs before they happen.</p> <p>Of course since this is python -- feel free to break rules, and to explore -- but be wary of projects that could grow tenfold, if the source code is missing discipline it will be a problem.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload