pylint or similar to test version-specific language constructs?

Steven D'Aprano steve+comp.lang.python at
Fri Jan 11 16:37:26 CET 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" <jkn_gg at> 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 


More information about the Python-list mailing list