Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > pylint or similar to test version-specific language constructs?

Reply
Thread Tools

pylint or similar to test version-specific language constructs?

 
 
jkn
Guest
Posts: n/a
 
      01-09-2013
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
 
Reply With Quote
 
 
 
 
Gisle Vanem
Guest
Posts: n/a
 
      01-10-2013
"jkn" <(E-Mail Removed)9.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

 
Reply With Quote
 
 
 
 
thenault@gmail.com
Guest
Posts: n/a
 
      01-11-2013
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 ((E-Mail Removed)) if you go that way.

Regards,

--
Sylvain
 
Reply With Quote
 
Terry Reedy
Guest
Posts: n/a
 
      01-11-2013
On 1/11/2013 3:29 AM, The Night Tripper wrote:
> Gisle Vanem wrote:
>
>> "jkn" <(E-Mail Removed)9.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

 
Reply With Quote
 
Dave Angel
Guest
Posts: n/a
 
      01-11-2013
On 01/11/2013 03:29 AM, The Night Tripper wrote:
> Gisle Vanem wrote:
>
>> "jkn" <(E-Mail Removed)9.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

 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      01-11-2013
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" <(E-Mail Removed)9.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
 
Reply With Quote
 
Dave Angel
Guest
Posts: n/a
 
      01-11-2013
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

 
Reply With Quote
 
jkn
Guest
Posts: n/a
 
      01-13-2013
Hi Dave

On 11 Jan, 15:06, Dave Angel <(E-Mail Removed)> 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
 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      01-13-2013
On Mon, Jan 14, 2013 at 4:56 AM, jkn <(E-Mail Removed)9.co.uk> wrote:
> Hi Dave
>
> On 11 Jan, 15:06, Dave Angel <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[pylint] why pylint wants only capitals identifiers? Giacomo Boffi Python 4 04-19-2010 04:30 PM
Any similar Webcam broadcasting site similar to youtube Chaudhry Nijjhar Computer Support 0 02-19-2008 11:48 PM
Writing an interpreter for language similar to python!! luvsat Python 5 03-02-2007 01:08 PM
Template language similar to examples... Edgard Riba Ruby 1 02-01-2006 09:28 PM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments