Thread: [Pydev-code] Getting started with PyDev scripting
Brought to you by:
fabioz
From: Joel H. <yo...@if...> - 2006-04-04 15:25:00
|
Hi! I'm trying learn Jython scripting for PyDev in order to implement feature= =20 request #1450378 (mine :-). http://sourceforge.net/tracker/index.php?func=3Ddetail&aid=3D1450378&grou= p_id=3D85796&atid=3D577332 Fabio gave me a neat starter guide and a code example from the cvs java s= ource=20 (see feature request page above), but I've got a few questions before I c= an=20 start getting productive. 1) How do I find out PyEdit object methods and data members? What is the best way of finding out the available members and data method= s of=20 an object in Jython scripts for PyDev? I'm a CPython programmer and I'm u= sed to=20 having dir(), help() and the inspect module for peeking into strange obje= cts,=20 but none of them seems to do me any good here. Afaik the help() function = is not=20 implemented in Jython 2.1, but why can't I import the inspect module? Als= o, why=20 does dir(editor) return an empty list? (example at the end) What's the=20 recommended way of finding out information on object methods and data mem= bers=20 in Jython? 2) Where do I find the source for the relevant superclasses? I tried browsing the PyDev source cvs for the answer to my previous quest= ion,=20 but as I'm not a java black belt I feel a little disoriented. PyEdit obje= cts=20 apparently have a .getSite() method (line 32 in pyedit_example2.py in the= =20 starter guide), but the org.python.pydev.editor.PyEdit class does not def= ine it. http://cvs.sourceforge.net/viewcvs.py/pydev/org.python.pydev/src/org/pyth= on/pydev/editor/PyEdit.java?rev=3D1.91&view=3Dmarkup PyEdit implements IPyEdit, but how do I get to the source for it (or some= docs)? 3) How do I affect code in the editor with only a PyEdit object? From the starter guide I understand that Pydev scripts communicate with = PyDev=20 using an editor object, but the code example I got from Fabio apparently = does=20 not. Instead it uses a PySelection object that it gets as its first argum= ent.=20 The PyEdit argument is apparently not used. This Jython scripting thing seems really powerful and I hope I'll be able= to=20 produce some nifty things with it once I'm up to speed. Cheers! /Joel Hedlund IFM Bioinformatics Link=F6ping University Example: $PYEDIT_SCRIPTS/pyedit_test.py: --------------------------------------------------------------------- assert cmd is not None assert editor is not None dir(editor) import inspect --------------------------------------------------------------------- Console output on save: --------------------------------------------------------------------- ---> reloading /.../pyedit_test.py [] Traceback (innermost last): File "<string>", line 1, in ? File "/<PATH_SNIPPED>/pyedit_test.py", line 4, in ? ImportError: no module named inspect --------------------------------------------------------------------- |
From: Fabio Z. <fa...@gm...> - 2006-04-04 16:13:58
Attachments:
pyedit_completedir.txt
|
import java def dirObj(obj): ret = [] found = java.util.HashMap() original = obj if hasattr(obj, '__class__') and obj.__class__ == java.lang.Class: #get info about superclasses classes = [] classes.append(obj) c = obj.getSuperclass() while c != None: classes.append(c) c = c.getSuperclass() #get info about interfaces interfs = [] for obj in classes: interfs.extend(obj.getInterfaces()) classes.extend(interfs) #now is the time when we actually get info on the declared methods and fields for obj in classes: declaredMethods = obj.getDeclaredMethods() declaredFields = obj.getDeclaredFields() for i in range(len(declaredMethods)): name = declaredMethods[i].getName() ret.append(name) found.put(name, 1) for i in range(len(declaredFields)): name = declaredFields[i].getName() ret.append(name) found.put(name, 1) #this simple dir does not always get all the info, that's why we have the part before #(e.g.: if we do a dir on String, some methods that are from other interfaces such as #charAt don't appear) d = dir(original) for name in d: if found.get(name) is not 1: ret.append(name) return ret for p in dirObj(editor.__class__): print p |
From: Fabio Z. <fa...@gm...> - 2006-04-04 17:03:51
Attachments:
pyedit_completedir.txt
|
import java def dirObj(obj): ret = [] found = java.util.HashMap() original = obj if hasattr(obj, '__class__') and obj.__class__ == java.lang.Class: #get info about superclasses classes = [] classes.append(obj) c = obj.getSuperclass() while c != None: classes.append(c) c = c.getSuperclass() #get info about interfaces interfs = [] for obj in classes: interfs.extend(obj.getInterfaces()) classes.extend(interfs) #now is the time when we actually get info on the declared methods and fields for obj in classes: declaredMethods = obj.getDeclaredMethods() declaredFields = obj.getDeclaredFields() for i in range(len(declaredMethods)): name = declaredMethods[i].getName() ret.append(name) found.put(name, 1) for i in range(len(declaredFields)): name = declaredFields[i].getName() ret.append(name) found.put(name, 1) #this simple dir does not always get all the info, that's why we have the part before #(e.g.: if we do a dir on String, some methods that are from other interfaces such as #charAt don't appear) d = dir(original) for name in d: if found.get(name) is not 1: ret.append(name) return ret for p in dirObj(editor.__class__): print p |
From: Joel H. <yo...@if...> - 2006-04-12 22:07:36
Attachments:
pyedit_assign_params_to_attributes.py
|
Alright... These are my first stumbling steps into the glorious realm of pydev scripting. It's supposed to be a little helper for assigning the values of method parameters to attributes of self with the same names, and it's activated through "Ctrl-2" followed by "a<Enter>" ("a" for "assign"). Today it quite happily displaces docstrings and probably also behaves badly by other fascinating means which I still haven't discovered. I'd appreciate any and all pointers I can get on all this, so I can continue in the right direction. Take care everybody! /Joel Hedlund |
From: Fabio Z. <fa...@gm...> - 2006-04-12 23:54:52
|
Hi Joel, Nicely done, works very well for me (asside from the docstring issue you mentioned), so... congratulations!!! The only thing that I saw that you shouldn't do is storing another editor reference in your class (self._oEditor), you should just use the editor variable directly (it will always be available in your namespace). Now the only thing missing is checking if there is some docstring. You can do that in the following way: Check if there is some ' or ", get its absolute position in the document and then you can use: from org.python.pydev.core.docutils import ParsingUtils ParsingUtils.eatLiterals(document, StringBuffer(), initialOffsetOfLiteral) The contents of the docstring will be on the passed StringBuffer and the returned value will be the absolute offset to the docstring end. So, what were your first impressions on pydev scripting? I'd really like to know ways to improve it... Probably creating a more 'pythonic' interface fo= r some common operations will be in that list, but this will come with time, so, aside from that, what do you think? Cheers, Fabio On 4/12/06, Joel Hedlund <yo...@if...> wrote: > > Alright... These are my first stumbling steps into the glorious realm of > pydev scripting. > > It's supposed to be a little helper for assigning the values of method > parameters to attributes of self with the same names, and it's activated > through "Ctrl-2" followed by "a<Enter>" ("a" for "assign"). Today it > quite happily displaces docstrings and probably also behaves badly by > other fascinating means which I still haven't discovered. > > I'd appreciate any and all pointers I can get on all this, so I can > continue in the right direction. > > Take care everybody! > /Joel Hedlund > > > assert cmd is not None > assert editor is not None > > if cmd =3D=3D 'onCreateActions': > import re > from org.eclipse.jface.action import Action #@UnresolvedImport > from org.eclipse.jface.dialogs import MessageDialog #@UnresolvedImport > from org.python.pydev.core.docutils import PySelection > from org.python.pydev.editor.actions import PyAction > > class ScriptUnapplicableError(Exception): > """Raised when the script is unapplicable to the current line.""" > def __init__(self, msg): > self.msg =3D msg > def __str__(self): > return self.msg > > class AssignToAttribsOfSelf(Action): > _oEditor =3D editor > _rOK =3D re.compile(r'^\s+def\s+\w+\(self.*\)\s*:\s*$') > def run(self): > oSelection =3D PySelection(self._oEditor) > sCurrentLine =3D oSelection.getCursorLineContents() > try: > if not self._rOK.match(sCurrentLine): > msg =3D "So far, only one-liner method def lines are > recognised by this script. The current line is not such a line." > raise ScriptUnapplicableError(msg) > oParamInfo =3D oSelection.getInsideParentesisToks(False) > lsParams =3D oParamInfo.o1 > iOffset =3D oParamInfo.o2 > if len(lsParams) =3D=3D 0: > msg =3D "This method def has no parameters, so > consequently there is nothing to assign to atributes." > raise ScriptUnapplicableError(msg) > sPreviousIndent =3D PySelection.getIndentationFromLine > (sCurrentLine) > sIndent =3D PyAction.getStaticIndentationString() > sTotalIndent =3D sPreviousIndent + sIndent > sTemplate =3D sTotalIndent + "self.%s =3D %s" > sNewLine =3D PyAction.getDelimiter(oSelection.getDoc()) > sAssignments =3D sNewLine.join([sTemplate % (s,s) for s in > lsParams]) > iLine =3D oSelection.getLineOfOffset(iOffset) > oSelection.addLine(sAssignments, iLine) > except ScriptUnapplicableError, e: > title =3D "Script Unapplicable" > header =3D "Script: Assign Method Parameters to Attributes= of > self\r\n\r\n" > MessageDialog.openInformation(editor.getSite().getShell(), > title, header + str(e)) > > editor.addOfflineActionListener("a", AssignToAttribsOfSelf(), 'Assign > method parameters to attributes of self', True) #the user can activate th= is > action with: Ctrl+2 ex2<ENTER> > > > |
From: Joel H. <yo...@if...> - 2006-04-13 08:24:05
|
Hi! > Nicely done, works very well for me (asside from the docstring issue > you mentioned), so... congratulations!!! Thanks! > The only thing that I saw that you shouldn't do is storing another > editor reference in your class (self._oEditor), you should just use > the editor variable directly (it will always be available in your > namespace). Right. > from org.python.pydev.core.docutils import ParsingUtils > ParsingUtils.eatLiterals(document, > StringBuffer(), > initialOffsetOfLiteral) Who put StringBuffer in my scope? I can see it's there but I didn't declare it? Is it a Jython thing? Where can I read up on this? Oh, and is there something similar for retrieving the contents of parantheses? I tried: iOffset = oSelection.absoluteCursorOffset oStrBuf = StringBuffer() print iOffset print ParsingUtils.eatPar(document, iOffset, oStrBuf) print oStrBuf which returns offset of the paranthesis that closes the closest nested paranthesised expression in which the cursor currently is placed, but oStrBuf is left empty. I was thinking maybe I should use this to detect parameters instead, since that might be an easy way of dealing with line continuations, comments and code directly after the scope opening colon on def lines. What do you think? > So, what were your first impressions on pydev scripting? It's great. It gives me great opportunity for customisations, which otherwise would be impossible (since I don't Java :-). It's all still a little bewildering since I'm not yet used to how the internals of neither eclipse or pydev work. The learning curve seems steep (but not vertical). The dir utils you posted proved to be life savers. It's a pity the code is cropped when viewed in the html repository at sourceforge, so maybe you could put it somewhere accessible so that people not currently on this list also can benefit from them? One impression is that there seem to be very little documentation. Maybe I've got myself to blame since I must admit I still haven't pulled down the pydev source. To my defense, I've been confined to WinXP the last couple of days and I don't really know how to cvs from that... On the other hand, this list has been a great help with speedy and constructive responses. > I'd really like to know ways to improve it... It's too early for me to tell, I think. I need to mess around with it for a while first, but I'll get back to you once I come up with something solid. Should I post those feature requests to this list or to the tracker at sourceforge? Now, back into the fray... :-) /Joel |
From: Fabio Z. <fa...@gm...> - 2006-04-13 10:48:11
|
> > > from org.python.pydev.core.docutils import ParsingUtils > > ParsingUtils.eatLiterals(document, > > StringBuffer(), > > initialOffsetOfLiteral) > > Who put StringBuffer in my scope? I can see it's there but I didn't > declare it? Is it a Jython thing? Where can I read up on this? It is a java thing -- comes from java.lang... Actually you should import it into your scope: from java.lang import StringBuffer. You can check its javadocs at: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/StringBuffer.html Oh, and is there something similar for retrieving the contents of > parantheses? I tried: > > iOffset =3D oSelection.absoluteCursorOffset > oStrBuf =3D StringBuffer() > print iOffset > print ParsingUtils.eatPar(document, iOffset, oStrBuf) > print oStrBuf > > which returns offset of the paranthesis that closes the closest nested > paranthesised expression in which the cursor currently is placed, but > oStrBuf is left empty. I was thinking maybe I should use this to detect > parameters instead, since that might be an easy way of dealing with line > continuations, comments and code directly after the scope opening colon > on def lines. What do you think? Actually, the current version seems nice to me... It actually uses the ParsingUtils to get the parents, so, it should be ok. Also, in the tuple you have in the return, 'tuple.o2' will give you the parenthesis end -- You can check that function at: http://cvs.sourceforge.net/viewcvs.py/pydev/org.python.pydev.core/src/org/p= ython/pydev/core/docutils/PySelection.java?view=3Dmarkup > So, what were your first impressions on pydev scripting? > > It's great. It gives me great opportunity for customisations, which > otherwise would be impossible (since I don't Java :-). It's all still a > little bewildering since I'm not yet used to how the internals of > neither eclipse or pydev work. The learning curve seems steep (but not > vertical). The dir utils you posted proved to be life savers. It's a > pity the code is cropped when viewed in the html repository at > sourceforge, so maybe you could put it somewhere accessible so that > people not currently on this list also can benefit from them? Sure... Actually, I have in my 'todo-list' doing a developers manual, on ho= w to get the code, so, I guess I'll put this there too. One impression is that there seem to be very little documentation. Maybe > I've got myself to blame since I must admit I still haven't pulled down > the pydev source. To my defense, I've been confined to WinXP the last > couple of days and I don't really know how to cvs from that... On the > other hand, this list has been a great help with speedy and constructive > responses. Well, actually most code has javadocs, so, probably doing at least a javado= c from pydev code and making it available would be a good addition to that. A= s for the cvs stuff, that developers manual would surely help -- It should be pretty easy getting the pydev code in Eclipse. > I'd really like to know ways to improve it... > > It's too early for me to tell, I think. I need to mess around with it > for a while first, but I'll get back to you once I come up with > something solid. Should I post those feature requests to this list or to > the tracker at sourceforge? If you want to elaborate on them, you can put it in this list (and put it later in the tracker), now, if you're sure of what you want, just toss it i= n the tracker . Cheers, Fabio |
From: Joel H. <yo...@if...> - 2006-04-13 13:37:01
|
Hi! I've cooked up a new version of my 'Assign method parameters to attributes of self' script. This one should be saner, neater, more helpful, and respectful of indent. I'm still very thankful for any hints or comments regarding anything in this code. I also have a few questions: 1) Is there some way of detecting whether or not there's a syntax error on the current line at sript execution? In the current form my script will happily propagate syntax errors from the def line, e.g: class moo: def cow(self, 1): (gives self.1 = 1 on execution) 2) Is there a bug in getInsideParentesisToks? If called with the string "(foo,)" then (the equivalent of) ['foo'] is returned. If called with the string "(foo, )" then (the equivalent of) ['foo', ''] is returned. The input values are equivalent in python, so shouldn't the returned values be equal? The reason I ask is related to my comment at line 71 in my attached script: # This can happen with legal def lines such as "def moo(self, ):" 3) Right now my script activates on "Ctrl-2" followed by "a<Enter>". I think what we initially discussed was having this as "Ctrl-2" followed by "a", which just requires swapping the True at the final line for a False. Which one should I use? The latter seems more convenient for me right now, but using it makes it impossible to execute other scripts whose names begin with "a". Is there an easy way for users to rebind script names to their needs? Who decides which script should have what name? Anyway, I'm really starting to like this pydev scripting thing. This'll be good, I'm sure. :-) Take care! /Joel Hedlund |
From: Fabio Z. <fa...@gm...> - 2006-04-13 15:28:44
|
> > > 1) > Is there some way of detecting whether or not there's a syntax error on > the > current line at sript execution? In the current form my script will > happily > propagate syntax errors from the def line, e.g: > > class moo: > def cow(self, 1): > > (gives self.1 =3D 1 on execution) Well, actually, you could, but that would be harder, mostly because you wan= t to do that even on other syntax errors (because you could do: editor.getAST= () and check its return for the abstract syntax tree with the results of the parsing, but it might fail in other errors, and not only in the current one), so, I wouldn't worry about this one, as the user would see the syntax error on that line anyway. 2) Is there a bug in getInsideParentesisToks? > If called with the string "(foo,)" then (the equivalent of) ['foo'] is > returned. If called with the string "(foo, )" then (the equivalent of) > ['foo', > ''] is returned. The input values are equivalent in python, so shouldn't > the > returned values be equal? Well, yes, I think so too ;-) Fixed for 1.0.6 The reason I ask is related to my comment at line 71 in my attached script: > # This can happen with legal def lines such as "def moo(self, ):" > > > 3) > Right now my script activates on "Ctrl-2" followed by "a<Enter>". I think > what > we initially discussed was having this as "Ctrl-2" followed by "a", which > just > requires swapping the True at the final line for a False. > > Which one should I use? The latter seems more convenient for me right now= , > but > using it makes it impossible to execute other scripts whose names begin > with > "a". Is there an easy way for users to rebind script names to their needs= ? > Who > decides which script should have what name? You can let it with True... If later something else appears it can be changed. The only way to rebind it currently is changing the script itself. And who decides is the script author ;-) Also, the script has 1 minor 'quirk': if your def line is the last line of the document (without any new-line in the end) -- fault of PySelection.addLine (which I just fixed, so, should work without this problem on 1.0.6). Cheers, Fabio |
From: Joel H. <yo...@if...> - 2006-04-14 01:32:40
|
> mostly because you want to do that even on other syntax errors Yes that's what I had in mind, really. Something that lets the script say "woah, clean up your code before running me!". > I wouldn't worry about this one, as the user would see the syntax > error on that line anyway. I think an IDE gives a more reliable impression if it refuses to propagate errors, but I can just as well leave it as it is if you think that's better. >> 2) Is there a bug in getInsideParentesisToks? > > Fixed for 1.0.6 Snappy! Me like :-) > And who decides is the script author ;-) Heh... Then I'll set it to False. I've got the power, yeah! ;-) > Also, the script has 1 minor 'quirk': if your def line is the last > line of the document (without any new-line in the end) -- fault of > PySelection.addLine (which I just fixed, so, should work without this > problem on 1.0.6). Oh. Forgot to fix that one. I'll do that (and some other things I noticed just now) and repost with a new version. Cheers! /Joel |
From: Joel H. <yo...@if...> - 2006-04-13 13:39:39
|
Hi! I beg to withdraw my previous statement about thin documentation. The source is definitely adequately documented for my tastes. And by the way... I can see from the source that there's a lot of work invested in this baby. Way to go, and keep up the good work! > It is a java thing -- comes from java.lang... Actually you should import it > into your scope: from java.lang import StringBuffer. Yes. On Ubuntulinux 5.10, eclipse 3.1.1 and pydev 1.0.4 I do have to import it. Under WinXP, eclipse <newest> and pydev 1.0.5 I didn't need to import it... Seems weird though. I must have imported it by mistake somewhere. I'll investigate some more and get bact to you if I can't track it down to some strangeness on my part. > Well, actually most code has javadocs, so, probably doing at least a javadoc > from pydev code and making it available Sorry. Don't know how to do that. > As for the cvs stuff, that developers manual would surely help -- It > should be pretty easy getting the pydev code in Eclipse. I pulled it down using command line cvs. If you're planning to put something about that in the developer manual maybe you're interested to know that the instructions at the CVS part of pydev@sourceforge didn't work for me. http://sourceforge.net/cvs/?group_id=85796 The login failed with this error message: $ cvs -d:pserver:ano...@cv...:/cvsroot/pydev login Logging in to :pserver:ano...@cv...:2401/cvsroot/pydev CVS password: cvs login: warning: failed to open /home/bioinfo/yohell/.cvspass for reading: No such file or directory However this did work: $ cvs -d:pserver:ano...@cv...:/cvsroot/pydev checkout . Cheers! /Joel |
From: Fabio Z. <fa...@gm...> - 2006-04-13 15:32:43
|
> > > > It is a java thing -- comes from java.lang... Actually you should impor= t > it > > into your scope: from java.lang import StringBuffer. > > Yes. On Ubuntulinux 5.10, eclipse 3.1.1 and pydev 1.0.4 I do have to > import it. > Under WinXP, eclipse <newest> and pydev 1.0.5 I didn't need to import > it... > Seems weird though. I must have imported it by mistake somewhere. I'll > investigate some more and get bact to you if I can't track it down to som= e > strangeness on my part. Well, remind that things are in a 'shared' interpreter for all scripts for an editor, so, if you had made some from java.lang import * in one script, all would have access to it (not something you'd like to rely on). > Well, actually most code has javadocs, so, probably doing at least a > javadoc > > from pydev code and making it available > > If you got it within an Eclipse project, just right-click it, and then export > javadoc. Cheers, Fabio |
From: Joel H. <yo...@if...> - 2006-04-14 01:36:34
|
> Well, remind that things are in a 'shared' interpreter for all scripts > for an editor, Yes. Will keep that in mind. > If you got it within an Eclipse project, just right-click it, and then > export > javadoc. Handy. Thanks! I have it that way now. I used the eclipse CVS support to pull down the pydev source to my XP machine, and it worked like a dream. Also very handy. :-) Take care! /Joel |
From: Don T. <nos...@gm...> - 2006-04-13 00:44:43
|
Joel Hedlund wrote: > Alright... These are my first stumbling steps into the glorious realm of > pydev scripting. > > It's supposed to be a little helper for assigning the values of method > parameters to attributes of self with the same names, and it's activated > through "Ctrl-2" followed by "a<Enter>" ("a" for "assign"). Today it > quite happily displaces docstrings and probably also behaves badly by > other fascinating means which I still haven't discovered. > > I'd appreciate any and all pointers I can get on all this, so I can > continue in the right direction. > Hi Joel: I have just installed your script and I guess I do not understand the use case. I place my mouse pointer in a function definition, hit ctrl-2, a, <enter> and I always get the message: "So far, only one-liner method def lines are recognised by this script. The current line is not such a line." I tried a one-liner: def fun(fred): foo = fred and still get the same result. In addition, Pydev extensions on my machine complains about lots of undefined symbols (cmd, editor, PySelection, PyAction, True and False). Sticking Fabio's trick if False: from org.python.pydev.editor import PyEdit #@UnresolvedImport cmd = 'command string' editor = PyEdit sorts out cmd and editor, but at the expense of another False failure. Adding #@UnresolvedImport to the ends of a couple of from lines fixes PySelection and PyAction. Fabio: I am pretty uneasy about these tricks to kill undefined symbols. I don't understand what is going on here, but it seems to work. It looks too much like magic. I don't understand why we have to lie on the from lines, or is this always the case with Jython and Pydev extensions? I don't think that True/False appeared in Python until 2.3 or 2.4 and Jython is 2.1. So, what is going on here? Do these scripts already have a bunch of things defined that is not apparant until they are executed, but the compiler cannot be told about them? Don. |
From: Fabio Z. <fa...@gm...> - 2006-04-13 02:07:56
|
Hi Don, I have just installed your script and I guess I do not understand the > use case. The use case is: class Foo: def m1(self, a,b): <-- it will create self.a =3D a, self.b =3D b > Fabio: > > I am pretty uneasy about these tricks to kill undefined symbols. I > don't understand what is going on here, but it seems to work. It looks > too much like magic. Well, that's just untill I make the scripting environment recognize all those tokens. You could actually create a jython project in your scripts an= d add all the eclipse jars to it, but I'd rather wait a little and have some check where you could say 'ok, I want to recognize as valid imports all the jars from Eclipse'. I don't understand why we have to lie on the from lines, or is this > always the case with Jython and Pydev extensions? As I said, you could configure your project with all that, but it would tak= e to much work to be good for using, so, given some time, I'll make it recognize that. I don't think that True/False appeared in Python until 2.3 or 2.4 and > Jython is 2.1. > > So, what is going on here? Do these scripts already have a bunch of > things defined that is not apparant until they are executed, but the > compiler cannot be told about them? Actually... sort of... False and True are only 2.3 onwards, but I add 2 tokens: False=3D0 and True=3D1 to the globals (in the same way I add the cm= d and the editor tokens). That's mostly because I was tired of always having to declare those in the top of a jython script, so, good thing I don't have to do that anymore ;-) Cheers, Fabio |
From: Joel H. <yo...@if...> - 2006-04-13 07:20:39
|
Hi! > I tried a one-liner: > > def fun(fred): foo = fred > > and still get the same result. Oh. Guess that was a bit ambiguous. By "method def one-liner" I mean a method def statement where the def keyword, parameters, and scope opening colon all live on the same line. I.e: no line continuations either using brackets or backslashes. Good: def moo(self, cow): (code here) Bad: def \ moo(self, cow): (code here) and I guess assuming no code after scope opening colon isn't such a great idea either. But anyway all this will be corrected once I learn how to script pydev properly. > Adding #@UnresolvedImport to the ends of a couple of from lines > fixes PySelection and PyAction. Oh. I didn't understand what it was at first (running plain pydev) but I'll fix it. > I don't think that True/False appeared in Python until 2.3 or 2.4 and > Jython is 2.1. Jython 2.2alpha1 is out if you're interested. Downloaded it yesterday. Thanks for the tips! /Joel |
From: Don T. <nos...@gm...> - 2006-04-13 16:13:44
|
Fabio Zadrozny wrote: > Well, remind that things are in a 'shared' interpreter for all scripts > for an editor, so, if you had made some from java.lang import * in one > script, all would have access to it (not something you'd like to rely on). > Fabio: As I understand it importing something that has already been imported does not really do anything, unlike reload. So, is there really any harm in having duplicate imports, and do you really need the guard around this import? if False: from org.python.pydev.editor import PyEdit #@UnresolvedImport cmd = 'command string' editor = PyEdit Don. |
From: Fabio Z. <fa...@gm...> - 2006-04-13 16:38:08
|
On 4/13/06, Don Taylor <nos...@gm...> wrote: > > Fabio Zadrozny wrote: > > > Well, remind that things are in a 'shared' interpreter for all scripts > > for an editor, so, if you had made some from java.lang import * in one > > script, all would have access to it (not something you'd like to rely > on). > > > > Fabio: > > As I understand it importing something that has already been imported > does not really do anything, unlike reload. > > So, is there really any harm in having duplicate imports, and do you > really need the guard around this import? No, no harm in it... Should be safe, so, no real need to do it. Cheers, Fabio |
From: Don T. <nos...@gm...> - 2006-04-15 01:08:47
|
Don Taylor wrote: > if False: > from org.python.pydev.editor import PyEdit #@UnresolvedImport > cmd = 'command string' > editor = PyEdit > > sorts out cmd and editor, but at the expense of another False failure. One way of getting rid of all of the True/False warnings in Pydev extensions is to use: if False: #@UndefinedVariable # None of this code will be executed, but it will stop Pydev # extensions from complaining about undefined variables. from org.python.pydev.editor import PyEdit #@UnresolvedImport cmd = 'command string' editor = PyEdit False = False #@UndefinedVariable True = True #@UndefinedVariable any further uses of True or False will not cause undefined variable errors because of these bogus assignments. Don. |
From: Fabio Z. <fa...@gm...> - 2006-04-16 21:44:33
|
> > > One way of getting rid of all of the True/False warnings in Pydev > extensions is to use: > > if False: #@UndefinedVariable > # None of this code will be executed, but it will stop Pydev Actually, what I do is put the True/False in the 'undefined' tab of code analysis (under 'consider the following names as globals). Cheers, Fabio |