![]() |
pylint or similar to test version-specific language constructs?
Hi all
I have to write python code which must run on an old version of python (v2.4) as well as a newer (v2.7). I am using pylint and would like to check if is possible to check with pylint the use of operators etc. which are not present in 2.4; the ternary operator springs to mind. I haven't found anything in pylint which indicates it can do this sort of check; am I missing anything? Other suggestions for this kind of checking welcome. Thanks Jon N |
Re: pylint or similar to test version-specific language constructs?
"jkn" <jkn_gg@nicorp.f9.co.uk> wrote:
> I have to write python code which must run on an old version of > python (v2.4) as well as a newer (v2.7). I am using pylint and would > like to check if is possible to check with pylint the use of operators > etc. which are not present in 2.4; the ternary operator springs to > mind. No idea about PyLint. Why not install Python 2.4 and test with that? Sounds safer IMHO. -gv |
Re: pylint or similar to test version-specific language constructs?
On Thursday, January 10, 2013 12:45:32 AM UTC+1, jkn wrote:
> Hi all > > I have to write python code which must run on an old version of > > python (v2.4) as well as a newer (v2.7). I am using pylint and would > > like to check if is possible to check with pylint the use of operators > > etc. which are not present in 2.4; the ternary operator springs to > > mind. > > > > I haven't found anything in pylint which indicates it can do this sort > > of check; am I missing anything? Other suggestions for this kind of > > checking welcome. Hi, there is no such checker in pylint yet, though it should be fairly easy to build one. The longer part being to identify all constructs that should be detected and their representation in the ast. Then pylint checkers are simple visitors. You'll get some help from the project mailing list (python-projects@lists.logilab.org) if you go that way. Regards, -- Sylvain |
Re: pylint or similar to test version-specific language constructs?
On 1/11/2013 3:29 AM, The Night Tripper wrote:
> Gisle Vanem wrote: > >> "jkn" <jkn_gg@nicorp.f9.co.uk> wrote: >> >>> I have to write python code which must run on an old version of >>> python (v2.4) as well as a newer (v2.7). I am using pylint and would >>> like to check if is possible to check with pylint the use of operators >>> etc. which are not present in 2.4; the ternary operator springs to >>> mind. >> >> No idea about PyLint. Why not install Python 2.4 and test >> with that? Sounds safer IMHO. > > I do have Python 2.4 installed; but I would like a checker that warned me > beforehand about trying to use constructs (like the ternary operator, > decorators) which are version-specific. Search each chapter of the reference manual (about 7) for 'version changed'. -- Terry Jan Reedy |
Re: pylint or similar to test version-specific language constructs?
On 01/11/2013 03:29 AM, The Night Tripper wrote:
> Gisle Vanem wrote: > >> "jkn" <jkn_gg@nicorp.f9.co.uk> wrote: >> >>> I have to write python code which must run on an old version of >>> python (v2.4) as well as a newer (v2.7). I am using pylint and would >>> like to check if is possible to check with pylint the use of operators >>> etc. which are not present in 2.4; the ternary operator springs to >>> mind. >> No idea about PyLint. Why not install Python 2.4 and test >> with that? Sounds safer IMHO. > I do have Python 2.4 installed; but I would like a checker that warned me > beforehand about trying to use constructs (like the ternary operator, > decorators) which are version-specific. > > J^n > Not sure what you mean by beforehand. Don't you run all your unit tests before putting each revision of your code into production? So run those tests twice, once on 2.7, and once on 2.4. A unit test that's testing code with a ternary operator will fail, without any need for a separate test. if it doesn't, then you've got some coverage gaps in your unit tests. -- DaveA |
Re: pylint or similar to test version-specific language constructs?
On Fri, 11 Jan 2013 10:06:30 -0500, Dave Angel wrote:
> On 01/11/2013 03:29 AM, The Night Tripper wrote: >> Gisle Vanem wrote: >> >>> "jkn" <jkn_gg@nicorp.f9.co.uk> wrote: >>> >>>> I have to write python code which must run on an old version of >>>> python (v2.4) as well as a newer (v2.7). I am using pylint and would >>>> like to check if is possible to check with pylint the use of >>>> operators etc. which are not present in 2.4; the ternary operator >>>> springs to mind. >>> No idea about PyLint. Why not install Python 2.4 and test with that? >>> Sounds safer IMHO. >> I do have Python 2.4 installed; but I would like a checker that warned >> me beforehand about trying to use constructs (like the ternary >> operator, decorators) which are version-specific. Decorators work fine in Python 2.4. > Not sure what you mean by beforehand. Don't you run all your unit tests > before putting each revision of your code into production? So run those > tests twice, once on 2.7, and once on 2.4. A unit test that's testing > code with a ternary operator will fail, without any need for a separate > test. You don't even need tests for the code that includes the ternary operator. The module simply won't compile in Python 2.4, you get a SyntaxError when you try to import it or run it. You don't need PyLint to check for *illegal syntax*. Python already does that. -- Steven |
Re: pylint or similar to test version-specific language constructs?
On 01/11/2013 10:37 AM, Steven D'Aprano wrote:
> On Fri, 11 Jan 2013 10:06:30 -0500, Dave Angel wrote: > >> <snip> > >> Not sure what you mean by beforehand. Don't you run all your unit tests >> before putting each revision of your code into production? So run those >> tests twice, once on 2.7, and once on 2.4. A unit test that's testing >> code with a ternary operator will fail, without any need for a separate >> test. > You don't even need tests for the code that includes the ternary > operator. The module simply won't compile in Python 2.4, you get a > SyntaxError when you try to import it or run it. > > You don't need PyLint to check for *illegal syntax*. Python already does > that. > You're right of course. But I can weasel out of it by saying that Python will only check it if the particular module is imported. I've seen equivalent bugs in real projects, where a release went out with one of its dynamic libraries not even present. Another thing that can stop Python from checking is if some naive programmer uses a bare except in production code. Both of these would show up in the simplest of unit testing code. -- DaveA |
Re: pylint or similar to test version-specific language constructs?
Hi Dave
On 11 Jan, 15:06, Dave Angel <d...@davea.name> wrote: > > Not sure what you mean by beforehand. *Don't you run all your unit tests > before putting each revision of your code into production? *So run those > tests twice, once on 2.7, and once on 2.4. *A unit test that's testing > code with a ternary operator will fail, without any need for a separate > test. > > if it doesn't, then you've got some coverage gaps in your unit tests. By 'beforehand' I meant 'before testing on my target 2.4 system; perhaps I should have been clearer in that I am running 2.7 on my 'development' platform, and 2.4 on my target. It would be painful to put 2.4 on my target system (although I continue to wonder about that...). So I was looking to catch such errors before migrating to the target. [Steven D'Aprano] > Decorators work fine in Python 2.4. Yes, I was just coming up with another example of a language construct which didn't exist at one point. > You don't even need tests for the code that includes the ternary > operator. The module simply won't compile in Python 2.4, you get a > SyntaxError when you try to import it or run it. In fact I had a misapprehension about this; for some reason (I thought I'd tried it) I thought such an error only got caught at runtime, not 'compile-time'. I now see that this is not the case, which means the athe problem is less of a concern than I thought. Thanks for the comments. Jon N |
Re: pylint or similar to test version-specific language constructs?
On Mon, Jan 14, 2013 at 4:56 AM, jkn <jkn_gg@nicorp.f9.co.uk> wrote:
> Hi Dave > > On 11 Jan, 15:06, Dave Angel <d...@davea.name> wrote: >> >> Not sure what you mean by beforehand. Don't you run all your unit tests >> before putting each revision of your code into production? So run those >> tests twice, once on 2.7, and once on 2.4. A unit test that's testing >> code with a ternary operator will fail, without any need for a separate >> test. >> >> if it doesn't, then you've got some coverage gaps in your unit tests. > > By 'beforehand' I meant 'before testing on my target 2.4 system; > perhaps I should have been clearer in that I am running 2.7 on my > 'development' platform, and 2.4 on my target. It would be painful to > put 2.4 on my target system (although I continue to wonder about > that...). So I was looking to catch such errors before migrating to > the target. Painful to put 2.4 on your dev, you mean? I've never done it, but I would expect that the old sources will compile against newer libraries with no problems. That's likely to be the easiest option. It's the language-level equivalent of watching for a thrown exception rather than asking forgiveness beforehand :) ChrisA |
| All times are GMT. The time now is 08:03 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.