<div>On Wed, Oct 13, 2010 at 12:10 PM, Seebs <span dir="ltr"><<a href="mailto:usenet-nospam@seebs.net" target="_blank">usenet-nospam@seebs.net</a>></span> wrote:</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div>On 2010-10-13, Jean-Michel Pichavant <<a href="mailto:jeanmichel@sequans.com" target="_blank">jeanmichel@sequans.com</a>> wrote:<br>
> If you wonder about some defects reported by such linters, you can then<br>
> ask in this list why something is not that good, because it may not be<br>
> always obvious.<br>
<br>
> 'pylint' is one them, pretty effective.<br>
<br>
</div>Okay, several questions about stuff pylint found.<br>
<br>
1.  If I have a message that I wish to print, it is quite possible<br>
that message + indentation exceeds 80 lines.  What's the idiomatic way<br>
to solve this?  Do I just break the string up into parts, or do I just<br>
accept that some lines are over 80 characters, or what?<br>
2.  It warns about **kw, both because the name is short and because of<br>
the "** magic".  I was previously advised that the name "kw" is canonical<br>
for that usage, in which case, why am I getting linted at?<br>
3.  More generally, the usage of **kw is probably not really right, but I'm<br>
not sure what to do.<br>
<br>
The issue here is as follows:<br>
<br>
In C, some functions have an optional argument with the curious trait that,<br>
if present, it is always of the same type.  e.g., open(2).  In my wrappers,<br>
I indicate this by declaring it as something like "...{mode_t mode}".  The<br>
intent is that in a declaration, this will turn into:<br>
        foo(blah blah blah, ... /* mode_t mode */)<br>
so there's an indication of why there's a "..." there.<br>
But C comments don't nest.  And there's a couple of points where I want to<br>
put the declaration in a comment.  So in those cases, I need to do something<br>
other than /*...*/:<br>
        /* foo(blah blah blah, ... mode_t mode) */<br>
<br>
The problem:  The determination of whether I wish to do this is at the level<br>
of the "represent this function in the following way" (Function.comment()),<br>
but the implementation is two layers down.  So right now, I am passing<br>
down 'comment = True' from the top level through, and I'm doing it using<br>
a **kw keyword argument.<br>
<br>
The rationale is that I could just use<br>
        def decl(comment = False):<br>
                ...<br>
but then the invocation:<br>
        func.decl(True)<br>
would be utterly opaque.  I want to name the thing I'm passing or otherwise<br>
indicate what it is.<br>
<br>
It could be that I am Doing This Wrong.  Is there a good idiom for labeling<br>
optional arguments, and passing them on (if they exist)?<br></blockquote><div><br></div><div>You can always name the arguments (the following work in 2.5 and 2.6, barring typos - the code is untested):</div><div><br></div>
<div>def func1(arg1, arg2):</div><div>    print arg1, arg2</div><div><br></div><div>> func1(arg2=1, arg1=2)</div><div>2 1</div><div><div>> func1(2, arg2=1)</div><div>2 1</div></div><div><br></div><div><div>def func2(arg1, arg2, optionalArg=3):</div>
<div>    print arg1, arg2, optionalArg</div></div><div><br></div><div>> func2(1, 2)</div><div>1 2 3</div><div>> func2(1, 2, optionalArg=4)</div><div>1 2 4</div><div>> func2(1, 2, 4)</div><div>1 2 4</div><div>> func2(arg2=1, arg1=2, optionalArg=4)</div>
<div>2 1 4</div><div><br></div><div>You can also mix and match:</div><div><br></div><div>def func1(arg1, arg2, arg3):</div><div>    print arg1, arg2, arg3</div><div><br></div><div>> func1(1, arg3=2, arg2=3)</div><div>1 3 2</div>
<div><div><br></div></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div></div><div><br>
-s<br>
--<br>
Copyright 2010, all wrongs reversed.  Peter Seebach / <a href="mailto:usenet-nospam@seebs.net" target="_blank">usenet-nospam@seebs.net</a><br>
<a href="http://www.seebs.net/log/" target="_blank">http://www.seebs.net/log/</a> <-- lawsuits, religion, and funny pictures<br>
<a href="http://en.wikipedia.org/wiki/Fair_Game_(Scientology)" target="_blank">http://en.wikipedia.org/wiki/Fair_Game_(Scientology)</a> <-- get educated!<br>
I am not speaking for my employer, although they do rent some of my opinions.<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br>