Pylint across Python versions

2014-02-10 Thread thomas . lehmann
Hi,

somebody who can tell me about pylint experiences across
different Python version.

Example:
I'm using a construct like this:

if sys.version.startswith(3.):
unicode = str

The reason is that Python 3 does not have this
function anymore but pylint yells for Python  3
about redefinition also it does not happen.

How to get forward with this?

Regards,
Thomas
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pylint across Python versions

2014-02-10 Thread Mark Lawrence

On 10/02/2014 11:39, thomas.lehm...@adtech.com wrote:

Hi,

somebody who can tell me about pylint experiences across
different Python version.

Example:
I'm using a construct like this:

if sys.version.startswith(3.):
 unicode = str

The reason is that Python 3 does not have this
function anymore but pylint yells for Python  3
about redefinition also it does not happen.


I've no idea what the above is saying but see below anyway.



How to get forward with this?

Regards,
Thomas



 import sys
 sys.version
'3.4.0b2 (v3.4.0b2:ba32913eb13e, Jan  5 2014, 16:23:43) [MSC v.1600 32 
bit (Intel)]'

 sys.version.startswith('3.')
True


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


--
https://mail.python.org/mailman/listinfo/python-list


Re: Pylint across Python versions

2014-02-10 Thread Chris Angelico
On Mon, Feb 10, 2014 at 10:39 PM,  thomas.lehm...@adtech.com wrote:
 Example:
 I'm using a construct like this:

 if sys.version.startswith(3.):
 unicode = str

 The reason is that Python 3 does not have this
 function anymore but pylint yells for Python  3
 about redefinition also it does not happen.

 How to get forward with this?

It's more common to spell that with a try/except. Does pylint complain
if you use this instead?

try:
unicode
except NameError:
unicode = str

Although it would be better to write your code for Python 3, and have
compatibility code at the top for Python 2. That would mean using
'str' everywhere, and then having this at the top:

try:
str = unicode
except NameError:
pass

That way, when you're ready to drop support for Python 2, you simply
delete the compat code and everything works. Otherwise, you have to
maintain messy code indefinitely.

Alternatively, to avoid redefinition at all, you could use your own
name everywhere:

try:
unicode_string = unicode
except NameError:
unicode_string = str

Use something less unwieldy if you prefer, but this avoids any chance
of collision :)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pylint across Python versions

2014-02-10 Thread Ned Batchelder

On 2/10/14 6:39 AM, thomas.lehm...@adtech.com wrote:

Hi,

somebody who can tell me about pylint experiences across
different Python version.

Example:
I'm using a construct like this:

if sys.version.startswith(3.):
 unicode = str

The reason is that Python 3 does not have this
function anymore but pylint yells for Python  3
about redefinition also it does not happen.

How to get forward with this?

Regards,
Thomas



Pylint may have a difficult time understanding what you are doing here. 
 You can use pylint comments to tell it to shut up when you know better.


But also, you might find it easier to use the six module from PyPI to 
handle these sorts of differences.  It's easier than doing it ad-hoc 
with your own logic.


--
Ned Batchelder, http://nedbatchelder.com

--
https://mail.python.org/mailman/listinfo/python-list