On 9/12/2013 1:17 PM, Terry Brown wrote:
On Thu, 12 Sep 2013 12:48:07 -0400
Jacob Peck <[email protected]> wrote:

On 9/12/2013 12:44 PM, Terry Brown wrote:
Stupid typeless language :-)
There are (hideously ugly) ways around that...
So at run time,

def executeScriptFromButton (self,b,buttonText,gnx):

you could have

   if ( type(b), type(buttonText), type(gnx) ) != ( LeoButton, str, str
   ):
       do_something()

but that's (a) too late, because it's the user's problem, not the
programmer's, and (b) not watertight anyway, if you swapped buttonText
and gnx, they're both str, so no catch there.  Let's ignore (b),
although I know subtyping str could address that in a typed language.
That's what I had in mind, though it could be moved out of the code with a function decorator. The python docs actually have one built for you: https://wiki.python.org/moin/PythonDecoratorLibrary#CA-3f6fec70c7d7bf3088b427eb9972af63d8b674ae_43

So just prepend the function def with `@accepts(LeoButton, str, str, debug=2)` and call it a day. But as I said, ugly.
Is that what you were thinking of, or is there something you can do
function annotations these days:

def executeScriptFromButton (self,b: LeoButton,buttonText: str,gnx: str):

? (http://www.python.org/dev/peps/pep-3107/)
Huh, that's neat.  Nice find.  The PEPs are filled with gems.
Hmm, I guess that's Python 3 only, so not a solution yet, even if there
was something that enforced it - just wondering what you had in mind.

Cheers -Terry

-->Jake

--
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to